[英]Regular expression to fetch mobile number
I am trying to fetch contact number from a string like "+19876543210 (mobile)" using below regex and its working fine for almost all format of number but not if number is starting with zero我正在尝试使用下面的正则表达式从诸如“+19876543210(移动)”之类的字符串中获取联系号码,并且它对于几乎所有格式的数字都可以正常工作,但如果数字以零开头则不行
var contact = "+19876543210 (mobile)";
// If var contact = "09876543219 then its not working"
contact.match(/^(\+?(\d{1,3}))?[-.\s]?\(?[1-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}/)
这有效:
/^(\+?(\d{1,3}))?[-.\s]?\(?[0-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.