Skip to content

Instantly share code, notes, and snippets.

@AllanPooley
Created July 25, 2018 00:48
Show Gist options
  • Save AllanPooley/4bda684b778cc01039f8daadf73f239d to your computer and use it in GitHub Desktop.
Save AllanPooley/4bda684b778cc01039f8daadf73f239d to your computer and use it in GitHub Desktop.
Australian Phone Number Validation in JavaScript
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