uwannadonkey Posted September 13, 2007 Share Posted September 13, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/69216-solved-restricting-letters/ Share on other sites More sharing options...
almightyegg Posted September 13, 2007 Share Posted September 13, 2007 $number = is_numeric($telephone); if($number == FALSE){ echo "Telephone number isn't a number!!"; } Quote Link to comment https://forums.phpfreaks.com/topic/69216-solved-restricting-letters/#findComment-347878 Share on other sites More sharing options...
Wuhtzu Posted September 13, 2007 Share Posted September 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/69216-solved-restricting-letters/#findComment-347879 Share on other sites More sharing options...
uwannadonkey Posted September 13, 2007 Author Share Posted September 13, 2007 i dont quite know who will signup to the site, thanks for your replies! both are amazing, but almightyegg provides the thing im looking for, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/69216-solved-restricting-letters/#findComment-347884 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.