Skip to content

zhaokw/RegexDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Regex Demo

By Kevin Zhao

US phone numbers are organized as (XXX)-YYY-ZZZZ, where XXX is the area code, YYY and ZZZZ are your main number bodies.

My function extractNumberFormat returns the standardized US number format from the input string, such that it follows the phone format. You can omit any hyphen or the parenthesis pair, add any space among XXX, YYY, ZZZZ. However, you cannot write only half of the parenthesis pair, or add space within numbers of XXX, YYY, ZZZZ.

Sample Inputs and Outputs

(212) -998 1212
212 9981212
212 998 - 1212
(212 -998 1212
(212)-9981-212
(212)-99-212

each returns:

(212)-998-1212
(212)-998-1212
(212)-998-1212
Not Valid US Phone
Not Valid US Phone
Not Valid US Phone

About

Parsing American Mobile Numbers with Regex

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages