daydreamer Posted March 8, 2008 Share Posted March 8, 2008 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. Quote Link to comment Share on other sites More sharing options...
daydreamer Posted March 8, 2008 Author Share Posted March 8, 2008 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? Quote Link to comment Share on other sites More sharing options...
daydreamer Posted March 8, 2008 Author Share Posted March 8, 2008 ah fixed it ! should be outside the brackets Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.