Check i.p. address format

Put an i.p. address in the box and click anywhere on the page. If it's no good, you'll get a javascript alert.

javascript
function check_ip_format(ip_addr) {
var valid=true;
var rE = new RegExp("/^((127)|(192)|(10).*)$/");
if (rE.test(ip_addr)) {
valid = false;
}
else {
var ip = ip_addr.split(".");
if(ip.length!= 4) {
valid = false;
}
else {
for (i=0; i<ip.length; i++) {
if (isNaN(ip[i])==true || ip[i] > 255 || ip[i] < 1) {
valid = false;
}
}
}
}
if (valid==false) {alert('Oy! Cut it out!');}
}
window.onload=function() {
document.getElementById('checkip').onchange=function() {
check_ip_format(this.value);
}
}
HTML
<h1>Check i.p. address format</h1>
<p>Put an i.p. address in the box and click anywhere on the page. If it's no good, you'll get a javascript alert.</p>
<p><input id="checkip"></p>

Comments

#1
2008-11-03 Debashis says :

Very good java script ..I use it...
Really working nicely..Thanks...

#2
2010-08-16 Mezgrman says :

Thanks a LOT dude! I was looking for EXACTLY this function! Thanks thanks thanks! smile

#3
2010-08-16 BonRouge says :

Cool. smile

Comment form

Please type the word 'wife' here:

BB code available :

  • [b]...[/b] : bold
  • [it]...[/it] : italic
  • [q]...[/q] : quote
  • [c]...[/c] : code
  • [url=...]...[/url] : url