我想允许用户使用Knockout Validation在电话号码字段中输入逗号。
有没有办法用Knockout做到这一点?目前,我使用validPhone
验证电话号码,如下面的代码:
this.PhoneNumber = ko.observable("").extend({
required: { message: "Enter valid Phone Number" },
validPhone: { message: 'Enter valid Phone Number' },
maxLength: { params: 12, message: "Phone Number only allows 12 characters" }
});
答案 0 :(得分:1)
您只需使用pattern
validation和regular expression。
这样的事情:
this.PhoneNumber = ko.observable("").extend({
required: { message: "Enter valid Phone Number"},
maxLength: { params: 12, message: "Phone Number only allows 12 characters" }
pattern: {
message: 'This isnt a valid phone number',
params: '^ your phone no. regular expression here $'
}