Skip to content

JS – Validate Phone Numbers


Warning: Use of undefined constant gad_content_tag_filter_replace - assumed 'gad_content_tag_filter_replace' (this will throw an Error in a future version of PHP) in /home/surfer_u/labs.andrewu.net/wp-content/plugins/web-ninja-google-analytics/webninja_ga.php on line 1813
var regexObj = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

if (regexObj.test(subjectString)) {
    var formattedPhoneNumber =
        subjectString.replace(regexObj, "($1) $2-$3");
} else {
    // Invalid phone number
}

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*