简体   繁体   中英

How to validate a specific format phone number?

My numbers looks like (###) ###-####

There is a space between the ) and the next digit or my number can look like (###) ###-#### ext ####

space after the ext and the )

Can someone tell me what regex needs to be performed to verify if either one is valid. Please note that the extension needs to be 4 digits if one is present.

I found this RegEx expression on the web

Regex.Match(number, @"^(\+[0-9]{9})$").Success

Unfortunately I am not very good at RegEx to understand or modify that

这个模式怎么样:

@"^\(\d{3}\) \d{3}-\d{4}( ext \d{4}){0,1}$"

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