Validating Phone number
The following example illustrates how to validate phone number using ereg.
<?php
function validate_phone($str)
{
//returns 1 if valid phone number (only numeric string), 0 if not
if (ereg(’^[[:digit:]]+$’, $str))
return 1;
else
return 0;
}
$input = “165.09″;
if(!validate_phone($input))
echo “phone number format incorrect: supply valid phone number”;
?>
In above example, input is passed in validate_phone() function. In that funtion, we are checking whether all characters are digits using ereg, if yes it will return 1 otherwise 0.
