daveh33 Posted January 3, 2008 Share Posted January 3, 2008 $number = $_POST['UserMobile']; if(ereg("^[0-9]{11}$", $number)) { $mobile = $number; } I use the above code at the moment to validate the input of a users mobile - the code above basically just checks that the variable is numeric only and has 11 digits. How can it be developed so that it also checks that the number starts 07? Quote Link to comment https://forums.phpfreaks.com/topic/84267-solved-validate-variable-numbers-only/ Share on other sites More sharing options...
GingerRobot Posted January 3, 2008 Share Posted January 3, 2008 Try: <?php $number = $_POST['UserMobile']; if(ereg("^07[0-9]{9}$",$number)){ $mobile = $number; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84267-solved-validate-variable-numbers-only/#findComment-429137 Share on other sites More sharing options...
awpti Posted January 3, 2008 Share Posted January 3, 2008 <?php $usermobile = $_POST['UserMobile']; if(strpos($usermobile, '07') === 0 && ctype_digit($usermobile)) { echo 'Good number'; } else { echo 'bad number'; } ?> Bit more bloated from a code perspective, but it's faster than using regex functions. If your site gets busy, this will be more efficient (in the long run) Quote Link to comment https://forums.phpfreaks.com/topic/84267-solved-validate-variable-numbers-only/#findComment-429140 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.