Created
April 6, 2011 05:11
-
-
Save wombleton/905175 to your computer and use it in GitHub Desktop.
ExtJS VType For Public IP Addresses Complying With RFC 1918
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
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