I want to check the range of ip address in a regular expression ,
I was using this way and it’s working so successfully
function validate_ip(ip)
{
// See if x looks like an IP address using our "almost IP regex".
var regex = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var match = regex.exec(ip);
if (!match) return false;
// Additional code to check that the octets aren't greater than 255:
for (var i = 1; i <= 4; ++i) {
if (parseInt(match[i]) > 255)
return false;
}
return true;
}
now i want to perform checking of the range and the syntax in just regular expression
can this be done ?
The most straightforward approach is to look at the different cases:
This will match numbers between 0 and 255, disallowing prefixed zeroes such as: 055.
If you want to exclude zero: