KevinM1 Posted January 12, 2007 Share Posted January 12, 2007 I have a simple form in which I ask the user to enter in the telephone number of their credit card company. I try validating that it's either a 16 digit number (normal telephone number) or a 17 digit number (telephone number beginning with a 1, like 1800 something). Unfortunately, it doesn't seem to be working as I keep getting my error message which is created if the field fails the test.My validation is:[code]<?php if(!empty($_POST['bank_num']) && preg_match("/^[0-9]{16,17}$/i", $_POST['bank_num'])){ $bankNum = $_POST['bank_num']; $bn = TRUE; } else{ $errMessage .= "Please enter your credit card's telephone number!<br />\n"; }?>[/code]I know I don't need to tell it to be case insensative in this case, but I wouldn't think that would be the cause of the error (especially as both validating one's home phone number and their credit card's CID seem to work correctly with it like that). Any ideas on why I'm getting my error message, even if I input the correct number of digits? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 12, 2007 Share Posted January 12, 2007 What are some examples of valid input? This works for me, echoing "OK":[code]<?php $_POST['bank_num'] = '1234567812345678'; if(!empty($_POST['bank_num']) && preg_match("/^[0-9]{16,17}$/", $_POST['bank_num'])){ echo "OK"; } else{ echo "Not OK"; }?>[/code] Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted January 12, 2007 Author Share Posted January 12, 2007 Turns out I'm an idiot...I should be checking for numbers 10-11 digits long. I need more caffiene....Thanks for responding! :) Quote Link to comment 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.