vue 表单校验密码
<el-form :model="form" :rules="rules">
<el-form-item label="密码" prop="invalidPwd">
<el-input v-model="form.invalidPwd"></el-input>
</el-form-item>
</el-form>
rules: { invalidPwd: [ { required: true, message: "旧密码不能为空", trigger: "blur" }, { required: true, validator: validatePass , trigger: "blur" }, ] }
var validatePass = (rule, value, callback) => {
//必须包含⼤⼩写字母、数字、特殊字符长度再9-16位之间
var regex = new RegExp("(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{9,16}");
if (value === "") {
callback(new Error("请输⼊密码"));
} else if (value.length < 9 || value.length > 16) {
callback(new Error("请输⼊9~16位密码"));
} else if (!regex.test(value)) {
callback(new Error("密码必须同时包含字母、数字和特殊字符其中三项且⾄少9位"));
} else {
callback();
}
};