Skip to content

Instantly share code, notes, and snippets.

@elijahmurray
Created June 17, 2014 18:26
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 elijahmurray/9d8e301b796b509de5ec to your computer and use it in GitHub Desktop.
Save elijahmurray/9d8e301b796b509de5ec to your computer and use it in GitHub Desktop.
Regex for Phone Validation
def format_phone_number(phone_number)
if phone_number.gsub(/\D/, '').match(/^1?(\d{3})(\d{3})(\d{4})/)
[$1, $2, $3].join('')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment