PhoneValidator

object PhoneValidator

Contains helper methods to verify validity of phone numbers, in various formats.

Some examples of valid phone numbers are:

"5233123298", // plain 10 digit
"12543240573", // 1 prefix
"1 254 353 5028", // with spaces
"1 (634) 234-8563", // with parenthesis, spaces, dashes
"(634)2325937", // parenthesis, no spaces
"937-273-0936", // only dashes
"932 323-7362" // space and dash

Some examples of invalid phone numbers are:

"52331232982", // too many numbers
"532734333", // too few numbers
"1234539563", // area code starts with 1
"0234659372", // area code starts with 0
"593 673 2846", // 2nd digit in area code cannot be 9
"(253) 144-8392", // 1st digit in 7-digit number cannot be 1
"(253) 012-4856" // 1st digit in 7-digit number cannot be 0

Functions

isValid
Link copied to clipboard
fun isValid(phoneNumber: String): Boolean
Checks if the given phone number is valid.
removeSpecialCharacters
Link copied to clipboard
fun removeSpecialCharacters(phoneNumber: String): String
Takes a given phone number and removes any parentheses, dashes, and spaces, as well as remove a "1" prefix.

Properties

VALIDATION_REGEX
Link copied to clipboard
val VALIDATION_REGEX: <ERROR CLASS>
The Regex used by the SDK to validate phone numbers.