I'm developing web using php and mysql. I want to validate phone number starting from 7 . How can i do that? Please help me.
How to test user entered phone number start from 7
Collapse
X
-
Do you mean you want to make sure the phone number starts with 7?
You could do this using ereg()
Or more simply you could just do:
[php]
$lcPhoneNumber = $_POST['number'] ; // I'm assuming the number comes from a form
$lcFirstChar = substr($lcPhone Number, 0, 1) ;
if($lcFirstChar == '7')
{
// success
}
else
{
// fail
}
[/php]
Any code you use should be wrapped in a bit more error checking to ensure there is a value set first of all but that's the basic idea.
The advantage of ereg is that you can apply more advanced checks to the data supplied in one expression.
Cheers
nathj
Comment