Skip to content

Instantly share code, notes, and snippets.

@bcoughlan
Created May 9, 2012 21:51
Show Gist options
  • Save bcoughlan/2649187 to your computer and use it in GitHub Desktop.
Save bcoughlan/2649187 to your computer and use it in GitHub Desktop.
jQuery validation - IP address
//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
}
}
}
@ReddyDivya
Copy link

I could send IP like 192.168.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment