Jump to content

Recommended Posts

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)) {

Link to comment
https://forums.phpfreaks.com/topic/74444-variable-validation-numbers-only/
Share on other sites

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>";
}

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

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.