Created
May 9, 2012 21:51
-
-
Save bcoughlan/2649187 to your computer and use it in GitHub Desktop.
jQuery validation - IP address
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
//Validation | |
jQuery.validator.addMethod('validIP', function(value) { | |
var split = value.split('.'); | |
if (split.length != 4) | |
return false; | |
for (var i=0; i<split.length; i++) { | |
var s = split[i]; | |
if (s.length==0 || isNaN(s) || s<0 || s>255) | |
return false; | |
} | |
return true; | |
}, ' Invalid IP Address'); | |
Usage: | |
jQuery("#myForm").validate({ | |
rules: { | |
name: { | |
validIP: true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I could send IP like 192.168.1.