Javascript Regular Expressions Validate Telephone Number

Description

Javascript Regular Expressions Validate Telephone Number

function isValidTelephoneNumber(telephoneNumber) {
    let telRegExp = /^(\+\d{1,3} ?)?(\(\d{1,5}\)|\d{1,5}) ?\d{3}?\d{0,7}( (x|xtn|ext|extn|pax|pbx|extension)?\.? ?\d{2-5})?$/i;
    return telRegExp.test( telephoneNumber );
}
let phoneNumber = "123-123-1231";

if (isValidTelephoneNumber(phoneNumber)) {
    console.log("Valid Phone Number");
} else {/*from   www . jav  a  2 s  . c  om*/
    console.log("Invalid Phone Number");
}



PreviousNext

Related