Validating Phone number

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.

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.