<a-form-item
field="password"
:rules="[
{ required: true, message: '请输入密码' },
{ minLength: 8, message: '密码长度不能小于8位' },
{
validator: customValidator,
message: '密码至少包含一个字母数字符号',
},
]"
:validate-trigger="['change', 'blur']"
hide-label
>
const customValidator = (value, callback) => {
// Your custom validation logic here
const isValid =
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/.test(
value
);
// Call the callback with an error message if validation fails
if (!isValid) {
callback('密码至少包含一个字母数字符号');
} else {
// Call the callback with no error if validation passes
callback();
}
};
ArcoUI中自定义正则校验使用方法
最新推荐文章于 2024-06-05 16:14:30 发布