Jump to content

Recommended Posts


    else if($password != $cpassword)               { $errors[] = 'Password fields did not match.'; }



    else if($addressLength == 0)               { $errors[] = 'Address field not filled out.'; }

 

i have a registration form, and i want to make it so that if telephone # != a number, then the registration wont go through, but using the format above, where the errors are posted on the next page load, how would i do that?

Link to comment
https://forums.phpfreaks.com/topic/69216-solved-restricting-letters/
Share on other sites

You will check the telephone number with regex... I don't know where you live and what your telephone numbers look like, but in Denmark telephone numbers consist of 8 digits. To validate such a number I would do this:

 

<?php

if(preg_match("/^[0-9]{8}$/",$telephone)) {
  echo "Valid phone number";
}
else {
  echo "Invalid phone number";
}
?>

 

 

almightyegg's solution is usable, it check to see if $telephone is a number but it can be any number of any length. With regex you can check for the length too... and even allow people to separate parts of the number by spaces, - or _ or whatever :)

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.