Regular expression to match phone numbers with country codes

前端 未结 5 1886
慢半拍i
慢半拍i 2021-01-16 06:37

This is the regular expression I use to match phone numbers like:

00 00 00 00 00
00 00 0 00 00 00 00
+00 0 00 00 00 00

(\\d{2}\\s+\\d{2}\\s+\\d{2}\\s+\\d{2}         


        
5条回答
  •  逝去的感伤
    2021-01-16 07:00

    Try this:

    var re = /^\+?(\d{1,2} ?)+$/g
    var phone = "00 00 00 00 00"; //"00 00 00 00 00x"; 
    if(!re.test(phone))
        alert("wrong phone pattern");
    

提交回复
热议问题