我正在尝试进行自定义验证,以检查客户名称。客户名称只能是字符和空格。这是我尝试过的:
<v-text-field
outline
label="Customer Name"
:counter="30"
maxLength="30"
:error-messages="fieldErrors('enquiryForm.customername')"
v-model="enquiryForm.customername"
@input="$v.enquiryForm.customername.$touch()"
@blur="$v.enquiryForm.customername.$touch()">
</v-text-field>
import { required, maxLength } from 'vuelidate/lib/validators'
export default {
mixins: [ validationMixin ],
validations: {
enquiryForm: {
customername: { required, maxLength: maxLength(30), validName }
},
validationMessages: {
enquiryForm: {
customername: {
required: 'Please enter Customer name',
maxLength: 'Maximum length should be 30 characters',
validName: 'Name must be alphabets and space'
}
},
methods: {
validName (name) {
var re = /^[a-zA-Z ]*$/;
return re.test(name);
}
}
我已经在Google中搜索,但找不到符合我要求的任何内容。