e164num
Version:
**Light validation and manipulation of E.164 phone numbers.**
12 lines (11 loc) • 477 B
JavaScript
/**
* Returns true if the given phone number is a valid partial E.164 phone number.
* Empty string is considered valid as a starting point for input.
* Returns false otherwise.
*
* @param partialE164PhoneNumber The partial E.164 phone number to validate.
*/
export const isValidPartialE164PhoneNumber = (partialE164PhoneNumber) => {
const PartialE164RegEx = /^((\+1\d{0,10})|(\+?)|(\+[2-9]{1}\d{0,14}))$/;
return PartialE164RegEx.test(partialE164PhoneNumber);
};