Skip to content

Instantly share code, notes, and snippets.

@wombleton
Created April 6, 2011 05:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wombleton/905175 to your computer and use it in GitHub Desktop.
Save wombleton/905175 to your computer and use it in GitHub Desktop.
ExtJS VType For Public IP Addresses Complying With RFC 1918
Ext.apply(Ext.form.VTypes, {
publicip: function(v) {
var errorMessage = 'Invalid public IP address',
i,
parts = [];
v = Ext.util.Format.trim(v || '').split('.');
for (i = 0; i < v.length; i++) {
var num = parseInt(v[i]);
if (Ext.isNumber(num) && num >= 0 && num <= 255) {
parts.push(num);
} else {
return errorMessage;
}
}
if (parts.length === 4) {
if (parts[0] === 127 || parts[0] === 10 || (parts[0] === 192 && parts[1] === 168) || (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31)) { // RFC 1918
return errorMessage;
} else {
return true;
}
} else {
return errorMessage;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment