Created
July 25, 2018 00:48
-
-
Save AllanPooley/4bda684b778cc01039f8daadf73f239d to your computer and use it in GitHub Desktop.
Australian Phone Number Validation in JavaScript
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
const isPhone = (phoneNumber) => { | |
const cleanedPhoneNumber = phoneNumber.replace(/-|\s/g, ''); // Remove spaces and hyphens before performing test | |
const pattern = new RegExp('^(?:\\+?(61))? ?(?:\\((?=.*\\)))?(0?[2-57-8])\\)? ?(\\d\\d(?:[- ](?=\\d{3})|(?!\\d\\d[- ]?\\d[- ]))\\d\\d[- ]?\\d[- ]?\\d{3})$'); | |
return pattern.test(cleanedPhoneNumber); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment