简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM