Validation for phone and mobile numbers

僤鯓⒐⒋嵵緔 提交于 2019-12-24 22:19:12

问题


I tried it on Google but not get proper RE.will someone help me to achieve this : Phone Number: (Country Code)-(City Code)-(Number) Mobile Number: (Country Code)-(Number)

obviously that should not take char. Please help me


回答1:


This is the site for regular expression. note it down for future reference, you won't ever be dissapointed

For phone numbers: http://regexlib.com/Search.aspx?k=phone%20number

now here are some samples from there

PhoneNumbers

  • ^[2-9]\d{2}-\d{3}-\d{4}$
  • (((\d{3}) ?)|(\d{3}-))?\d{3}-\d{4}
  • (([0-9]{2}|0{1}((x|[0-9]){2}[0-9]{2})))\s*[0-9]{3,4}[- ]*[0-9]{4}

Mobiles:

  • ^[+]447\d{9}$
  • ^(+44\s?7\d{3}|(?07\d{3})?)\s?\d{3}\s?\d{3}$

Hope it helps



来源:https://stackoverflow.com/questions/2206329/validation-for-phone-and-mobile-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!