Skip to content

Instantly share code, notes, and snippets.

@XenRevo
Forked from bcoughlan/validation.js
Created January 14, 2016 03:09
Show Gist options
  • Save XenRevo/fa7eda6667c932432a94 to your computer and use it in GitHub Desktop.
Save XenRevo/fa7eda6667c932432a94 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
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment