Created
January 10, 2012 22:49
-
-
Save Rio517/1591694 to your computer and use it in GitHub Desktop.
Add method to Jquery Validate 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("phoneUS", function(phone_number, element) { | |
phone_number = phone_number.replace(/\s+/g, ""); | |
return this.optional(element) || phone_number.length > 9 && | |
phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); | |
}, "Please specify a valid phone number"); | |
// Source: http://docs.jquery.com/Plugins/Validation/CustomMethods/phoneUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<asp:TextBox ID="txtPhone" runat="server" />
<asp:Button ID="btnValidate" runat="server" Text="Validate" />