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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.