String Validation for IPs

[Total: 0    Average: 0/5]

This will compare the input string to that of a known IP address.

Head Code:

<script>
function findIt()
{
  /* method 1 */
  var _form=document.myform;
  var ip=_form.ip.value;
  var ip_parts=ip.split(".");
  var result=ip_parts[0]+"."+ip_parts[1]+"."+ip_parts[2];
  _form.result1.value=result;
  _form.result1b.value=(result=="213.181.60");

  /* method 2 */
  var _form=document.myform;
  var ip=_form.ip.value;
  var sub_part=ip.substr(0,10);
  _form.result2.value=sub_part;
  _form.result2b.value=(sub_part=="213.181.60");
}
</script>

Body Code:

<form name=myform>
<input type=text name=ip value="213.181.60.129">
<input type=button onclick="findIt()">
<BR />
Method1:<input type=text readonly onfocus="this.blur()" name=result1
value="?">
 Match 213.181.60?<input type=text readonly onfocus="this.blur()"
name=result1b value="?">
<BR />
Method2:<input type=text readonly onfocus="this.blur()" name=result2
value="?">

 Match 213.181.60?<input type=text readonly onfocus="this.blur()"
name=result2b value="?">
</form>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *