jQuery 验证方法 Phone 数字以加号开头
jQuery Validation Method Phone number begin with plus mark
我已经写了这个方法来验证 phone 以 plus 标记开始但是它不起作用,有人可以解释这个问题谢谢大家,
jQuery.validator.addMethod("fnType", function (phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.match(/^\+\d{8,}$/);
}, "Please specify a valid number");
$("#EditView").validate({
rules: {
phone_work: {
fnType: true,
minlength: 10
}
}
国际phone号码可以这样查询:
/^\+(?:[0-9] ?){6,14}[0-9]$/
解释:
^ # Assert position at the beginning of the string.
\+ # Match a literal "+" character.
(?: # Group but don't capture:
[0-9] # Match a digit.
\x20 # Match a space character
? # between zero and one time.
) # End the noncapturing group.
{6,14} # Repeat the group between 6 and 14 times.
[0-9] # Match a digit.
$ # Assert position at the end of the string.
使用这个
$.validator.addMethod('fnType', function(value, element) {
return value.match(/^\+(?:[0-9] ?){6,14}[0-9]$/);
},'Enter Valid phone number');
我已经写了这个方法来验证 phone 以 plus 标记开始但是它不起作用,有人可以解释这个问题谢谢大家,
jQuery.validator.addMethod("fnType", function (phone_number, element) {
phone_number = phone_number.replace(/\s+/g, "");
return this.optional(element) || phone_number.match(/^\+\d{8,}$/);
}, "Please specify a valid number");
$("#EditView").validate({
rules: {
phone_work: {
fnType: true,
minlength: 10
}
}
国际phone号码可以这样查询:
/^\+(?:[0-9] ?){6,14}[0-9]$/
解释:
^ # Assert position at the beginning of the string.
\+ # Match a literal "+" character.
(?: # Group but don't capture:
[0-9] # Match a digit.
\x20 # Match a space character
? # between zero and one time.
) # End the noncapturing group.
{6,14} # Repeat the group between 6 and 14 times.
[0-9] # Match a digit.
$ # Assert position at the end of the string.
使用这个
$.validator.addMethod('fnType', function(value, element) {
return value.match(/^\+(?:[0-9] ?){6,14}[0-9]$/);
},'Enter Valid phone number');