![](/img/trans.png)
[英]Validation for 10 digit mobile number and Showing Color On Input If Invalid
[英]Phone number validation which contains +** ***-***-**** (Plus following with Two digit country code with 10 digit mobile number)
我正在使用具有包含手機號碼字段的表單的功能。 要求是手機號碼字段采用以下格式:
+** ***-***-****
(再加上兩位數字的國家代碼和10位的手機號碼)我嘗試使用以下正則表達式,但無法產生所需的結果。
ng-pattern="/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/"
有人可以指導我嗎?
嘗試這個。
function phonenumber(inputtxt) { var phoneno = /^\\+[0-9]{2}-[0-9]{3}-[0-9]{3}-[0-9]{4}$/; if(inputtxt.match(phoneno)) { //return true; alert("true"); } else { //alert("message"); //return false; alert("false"); } } phonenumber("+91 111 111 1111"); phonenumber("+11-223-333-4444"); phonenumber("984656462464");
如果您想像+91 333 333 4444之間接受空格或點,則可以將?[-]更改為?[-。 ]
使用此正則表達式: ng-pattern="/^\\+[0-9]{5}-[0-9]{3}-[0-9]{4}$/"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.