2015-03-13 61 views
0

我寫了這個方法以驗證電話開始馬克但它不能正常工作,能有人請解釋這個問題謝謝大家,jQuery驗證方法電話號碼開頭加號

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 
     } 
    } 

回答

1

使用此

$.validator.addMethod('fnType', function(value, element) { 
return value.match(/^\+(?:[0-9] ?){6,14}[0-9]$/); 
},'Enter Valid phone number'); 

Click Here for more information

2

一個INTERNATION電話號碼可以檢查這樣的:

/^\+(?:[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.