Skip to content

Latest commit

 

History

History
23 lines (22 loc) · 930 Bytes

README.md

File metadata and controls

23 lines (22 loc) · 930 Bytes

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