Jump to content

validation problem.


daydreamer

Recommended Posts

trying to validate a mobile number.

if the string is not a number, or not 11 characters long, and error should be set/displayed.

 

if i enter in letters, the error is shown. if i enter in any amount of numbers, the script runs. It shouldn't unless the number entered is 11 digits.

 

<?php
                        $mobile = $_POST['msisdn'];	
		$mobilelength = strlen($mobile);
		echo "mobile length is $mobilelength";
		if( (!is_numeric($mobile)) ||(!$mobilelength==11) )  //HERE is where i am having troubles i think
			{$errors = "11 digit UK mobile numbers only.";}   //is_numeric($mobile) returns true 4 numerics

		if(isset($errors)){
     			$errors = nl2br($errors);         //nl2br formats /n into </br> for html display
      			include $_SERVER['DOCUMENT_ROOT'].'boxes/verify.php';
		$errors = NULL; //reset for next post
              	        exit();	
      			}
?>

 

 

Any body know whats wrong?! thanks.

Link to comment
https://forums.phpfreaks.com/topic/95093-validation-problem/
Share on other sites

ok. maybe i should simplyfy!

I have this code.

<?php
       $mobilelength = strlen($mobile);
        if( (!is_numeric($mobile)) ||(!$mobilelength==11) )  //HERE is where i am having troubles i think
 {$errors = "11 digit UK mobile numbers only.";}   //is_numeric($mobile) returns true 4 numeric
?>

 

why does the if clause not set $errors when $mobilelength is not 11?

 

Link to comment
https://forums.phpfreaks.com/topic/95093-validation-problem/#findComment-487121
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.