View Single Post
Old 11-14-2012, 01:35 AM   PM User | #1
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
Validating a UK telephone number.

Hi I am in the process of validating my post data and have come to the phone number field.

I'm not quite sure how to approach this.

When I get to that part of my switch, I send it through the intval() function. This seems to take of the 0 on the beginning of the string.

I decided to leave it as a string, and then use settype() just before doing my database stuff.

Here is my code relating to the phone number:
PHP Code:
case "phone":
    
$num_len strlen($value);
    if(!
ctype_digit($value)){
        
$errors[] = "You can only enter digits into the phone field.";
    }
    if(
$num_len != 11){
        
$errors[]  = "Your telephone number must be 11 digits.";
    }
    die();
break; 
I also did a bit of research and found UK landline and mobile numbers contain 11 digits, and the landlines range from 01200 up to 01997 (with the exception of around 50 which are 'not in use' (according to wikipedia)).

Anyone got any suggestions on how to tackle this?

Thank you for any feedback.

Kind regards,

LC.

Last edited by LearningCoder; 11-14-2012 at 01:43 AM..
LearningCoder is offline   Reply With Quote