Created
May 31, 2017 04:56
-
-
Save hengkiardo/eb6e917ea5c8ea8038d872c3b1a9277c to your computer and use it in GitHub Desktop.
Custom method to jQuery Validation Plugin for Phone Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.validator.addMethod("phoneno", function(phone_number, element) { | |
phone_number = phone_number.replace(/\s+/g, ""); | |
return this.optional(element) || phone_number.length > 9 && | |
phone_number.match(/^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/); | |
}, "<br />Please specify a valid phone number"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment