I have a number field on my form and i want to validate it with php.
But i need condition to see if its a mobile or a UK number.
I have the theory behind it down, where in respect i have to check the numstring count to see if it matches 11 or 12 numeric characters. but the thing is, people write out their numbers different like some people prefere to write mobile numbers out as 00000 000 000 and some 00000000000 same with land lines, Just trying to find the code to validate if its a number.
I was just wondering how i would go about the differences in number input?
Ben
Page 1 of 1
PHP number validation
#2
Posted 03 August 2009 - 06:53 PM
you could try preg_match and also strip the spaces not sure the code but something like stripslashes
#3
Posted 03 August 2009 - 06:54 PM
Simple, just strip out the whitespace characters.
It doesn't matter how people enter them, just run a validation that removes whitespace, that way all numbers entered will be returned as a 11/12 sole digit string.
Eg:
It doesn't matter how people enter them, just run a validation that removes whitespace, that way all numbers entered will be returned as a 11/12 sole digit string.
Eg:
preg_replace(' ','',$NUMBER_VARIABLE);
#4
Posted 03 August 2009 - 07:01 PM
SLGWN2P, on 03 August 2009 - 06:54 PM, said:
Simple, just strip out the whitespace characters.
It doesn't matter how people enter them, just run a validation that removes whitespace, that way all numbers entered will be returned as a 11/12 sole digit string.
Eg:
It doesn't matter how people enter them, just run a validation that removes whitespace, that way all numbers entered will be returned as a 11/12 sole digit string.
Eg:
preg_replace(' ','',$NUMBER_VARIABLE);
Didn't think it would be as simple as that, should be easy enough to implement
Thanks again.
#5
Posted 04 August 2009 - 10:12 AM
$phone = ereg_replace('[^0-9]', '', $_POST['phone']);
if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) {
echo 'Please enter your phone number correctly';
}
Share this topic:
Page 1 of 1
Help



















