Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Form Validation

JJAYCHEN edited this page Dec 11, 2019 · 2 revisions

Rules

ElementUI 自带了表单验证规则的功能。更多例子可以参考:https://www.jianshu.com/p/6a29e9e51b61

rules: {
//这是一个邮箱的验证规则
  email: [
    {
      required: true,          //是否必填
      message: "请输入邮箱地址", //错误提示信息
      trigger: "blur"          //检验方式(blur为鼠标点击其他地方,)
    },
    {
      type: "email",                //要检验的类型(number,email,date等)
      message: "请输入正确的邮箱地址",
      trigger: ["blur", "change"]   //检验方式(change为检验的字符变化的时候)
    }
  ],
  phone: [
    {
      required: true,
      pattern: /^1[34578]\d{9}$/,           //可以写正则表达式
      message: "目前只支持中国大陆的手机号码",
      trigger: "blur"
    }
  ],
}
Clone this wiki locally