Skip to content

Instantly share code, notes, and snippets.

@alanbsmith
Created January 15, 2018 21:34
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 alanbsmith/03dc52bd82b77a47b0ad8171fc256146 to your computer and use it in GitHub Desktop.
Save alanbsmith/03dc52bd82b77a47b0ad8171fc256146 to your computer and use it in GitHub Desktop.
// lib/validatePhone.js
function validatePhone(phoneNumber) {
// validate there are no characters
if (/[a-zA-Z]/.test(phoneNumber)) {
return false;
}
// validate there are enough numbers
const cleanNumber = phoneNumber.replace(/\s|\D/g, "");
return cleanNumber.length === 10;
};
export default validatePhone;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment