Skip to content

Instantly share code, notes, and snippets.

@leongaban
Created May 4, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leongaban/153f9f564ab08705a322db500ef16d0d to your computer and use it in GitHub Desktop.
Save leongaban/153f9f564ab08705a322db500ef16d0d to your computer and use it in GitHub Desktop.
Phone number formatting in Javascript
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