Regular expressions for IP addresses two examples of IP regular expressions are provided below, examples of IP addresses are verified, and legitimate IP addresses are printed.
Regular expressions for IP addresses
Here are two examples of IP regular expressions, examples of IP address authentication, and the legitimate IP address to print out.
*/
Check the IP address of the regular expression Example 1.
$arr _ip = Array (
"127.0.0.1",
"218.206.10.123",
"192.221.515.0",
"123.0.0.0.1",
" -12.255.0.10",
"10.9c.132.69",
"255.10.10.255"
);
foreach ($arr _ip as $ip)
{
if (Validateip ($IP))
{
echo "$ip is the correct IP address ";
echo "
";
}
Else
{
echo "$ip is not the correct IP address";
echo "
";
}
}
function Validateip ($IP)
{
$iparray = Explode (".", $ip);
for ($i =0; $i<>
{
if ($iparray [$i]>255)
return (0);
}
Return Ereg ("[0-9]{1,3}.[ 0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3} ", $ip);
}
Check the IP address of the regular expression Example 2.
$arr _ip = Array (
"127.0.0.1",
"218.206.10.123",
"192.221.515.0",
"123.0.0.0.1",
" -12.255.0.10",
"10.9c.132.69",
"255.10.10.255"
);
foreach ($arr _ip as $ip)
{
if (Validateip ($IP))
{
echo "$ip is the correct IP address ";
echo "
";
}
Else
{
echo "$ip is not the correct IP address";
echo "
";
}
}
function Validateip ($IP)
{
$iparray = Explode (".", $ip);
for ($i =0; $i<>
{
if ($iparray [$i]>255)
return (0);
}
Return Ereg ("^[0-9]{1,3}.[ 0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}$ ", $ip);
}
http://www.bkjia.com/PHPjc/631361.html www.bkjia.com true http://www.bkjia.com/PHPjc/631361.html techarticle Regular expressions for IP addresses two examples of IP regular expressions are provided below, examples of IP addresses are verified, and legitimate IP addresses are printed. The regular of the IP address ...