Created
May 4, 2017 16:01
-
-
Save leongaban/153f9f564ab08705a322db500ef16d0d to your computer and use it in GitHub Desktop.
Phone number formatting in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numberVerified = (number) => R.isEmpty(number) ? false : number.match(/^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/); | |
const formatPhone = (number) => { | |
// http://stackoverflow.com/questions/6204867/fastest-way-to-remove-hyphens-from-a-string-js | |
const new_number = number.replace(/-/g, ''); | |
return Number(new_number); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment