Jump to content

[SOLVED] restricting letters


uwannadonkey

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.