SoFunction
Updated on 2025-04-05

Element UI Custom regular expression verification method

As shown below:

//Specify the verification form valiForm of the data center, verification rules rules<el-form :model="valiForm" :rules="rules" ref="valiForm" label-width="100px" class="demo-valiForm">

  <el-form-item label="name:" :label-width="formLabelWidth" prop='name'>
   <el-input v-model=""></el-input>
  </el-form-item>

</el-form>
//The add('valiForm') method needs to pass the verification form name<el-button type="primary" @click="add('valiForm')">Confirm Certainly</el-button>
data () {
 let nameRule1 = (rule, value, callback) => {
  let regExp = //;
  if ((value) === false) {
   callback(new Error('Not passing the regular'));
  } else {
   callback();
  }
 };

 return {
  valiForm: {
   name: ''
  },
  rules: {
   name: [
   { required: true, message: 'Please enter a name', trigger: 'blur' },
   { min: 5, max: 10, message: 'Length between 5 and 10 characters', trigger: 'blur' },
   { validator: nameRule1, trigger: 'blur' }
   ]
  }

 };
 },
methods:{
 add(formName) {
  this.$refs[formName].validate((valid) => {
  if (valid) {
   //Execute by verification  } else {
   //Verification failed to execute   ('error submit!!');
   return false;
  }
  });
 }
}

The above Element UI custom regular expression verification method is all the content I share with you. I hope you can give you a reference and I hope you can support me more.