daveh33 Posted October 23, 2007 Share Posted October 23, 2007 The code I am using is $number = $_POST['UserMobile']; if(ereg("^[0-9]{19}$", $number)) { $mobile = $number; } else { echo "Invalid phone number - please go back and try again<P>"; } This works - but if the number is less than 19 digits it displays the "invalid phone number.." I want it so it accepts it if its up to 19 digits What changes need to be made to if(ereg("^[0-9]{19}$", $number)) { Quote Link to comment https://forums.phpfreaks.com/topic/74444-variable-validation-numbers-only/ Share on other sites More sharing options...
only one Posted October 23, 2007 Share Posted October 23, 2007 Check the strlen() manual. and the eregi() manual i think this is what you were trying too do with the code: $number = $_POST['UserMobile']; if(ereg("^[0-9]{20}$", $number)) { $mobile = $number; } else { echo "Invalid phone number - please go back and try again<P>"; } Quote Link to comment https://forums.phpfreaks.com/topic/74444-variable-validation-numbers-only/#findComment-376108 Share on other sites More sharing options...
Zane Posted October 23, 2007 Share Posted October 23, 2007 ^[0-9]{19}$ you can set a range within the braces from whatever to whatever ^[0-9]{1,19}$ will set a range from 1 to 19 numbers Quote Link to comment https://forums.phpfreaks.com/topic/74444-variable-validation-numbers-only/#findComment-376114 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 All mobile numbers are 11 digits arn't they? and they all have to start 07 under current regulations. Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/74444-variable-validation-numbers-only/#findComment-376141 Share on other sites More sharing options...
daveh33 Posted October 23, 2007 Author Share Posted October 23, 2007 The form is requesting an number in international format and is just not restricted to the UK - therefore UK numbers start 447 , but to allow other international mobile numbers to be accepted the form needs to handle up to 19 digits. ^[0-9]{1,19}$ works Thanks for that code Quote Link to comment https://forums.phpfreaks.com/topic/74444-variable-validation-numbers-only/#findComment-376146 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.