PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am making a form, and one of my fields is telephone number.
I have a check below to make sure it contains numbers.
It works if i put e.g. 12343212 but does not work if i put 01442 847392.
Is there a way to make it work?
<?php
function check($num) {
$num = str_replace(" ", "", $num); // gets rid of the spaces
if(!empty($num) && is_numeric($num) && strlen($num) == "8") { // checks if is not empty, a number and the length is 8 numbers
return TRUE; // returns true
} else {
return FALSE; // returns false, you can die() the script or something then
}
}
$no = $_POST['homtel'];
if(check($no)) {
echo "phone number is valid!";
}
?>
That also should do fine...
-Nay
Last edited by Nay on Wed Oct 08, 2003 8:00 am, edited 1 time in total.
i have other code in my script to check if not empty, but it will not work if i put the area code then a space and then the phone number.. I need the area code in as well you see. but i dont think is_numeric allows a space..