jcadima
6/25/2015 - 9:49 PM

Validate Phone Numbers

Validate Phone Numbers

// ref: http://stackoverflow.com/questions/4338267/validate-phone-number-with-javascript


//  INVALID PHONE NUMBER
if (phone == null || phone == "" ||  validatePhone(phone) == false ) {
   sweetAlert("Oops!", "Please Enter a valid Phone Number.", "error");
    return false;
}	


function validatePhone(phone) {
    var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
    return re.test(phone);
}


Valid formats:

(123) 456-7890
123-456-7890
123.456.7890
1234567890
+31636363634
075-63546725