-
-
Save alanbsmith/03dc52bd82b77a47b0ad8171fc256146 to your computer and use it in GitHub Desktop.
This file contains 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
// 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