I have developed code of how to validate IP Address.
Script
<script type="text/javascript"
src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js">
</script>
<script type="text/javascript" src=
"http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js">
</script>
<script type="text/javascript">
$(function() {
$.validator.addMethod('IP4Checker', function(value) {
var ip = "^(?:(?:25[0-5]2[0-4][0-9][01]?[0-9][0-9]?)\.){3}" +
"(?:25[0-5]2[0-4][0-9][01]?[0-9][0-9]?)$";
return value.match(ip);
}, 'Invalid IP address');
$('#form1').validate({
rules: {
ip: {
required: true,
IP4Checker: true
}
}
});
});
</script>
HTML
<input id="ip" name="ip" type="text" />
<input id="Submit1" type="submit" value="submit" />
This script is working good but have one problem this script only check the IP block 0-255 numbers when i enter 100.100.100
it accept the IP address also when I enter any numeric value like 1234567
it also accept this value as IP address. so please help me regarding this problem
Thanks