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. Link to comment https://forums.phpfreaks.com/topic/95093-validation-problem/ 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? Link to comment https://forums.phpfreaks.com/topic/95093-validation-problem/#findComment-487121 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 Link to comment https://forums.phpfreaks.com/topic/95093-validation-problem/#findComment-487125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.