suttercain Posted April 4, 2007 Share Posted April 4, 2007 Hello, I am trying to use form validation to verify a zip code: <?php if ($_POST["zip_code"] == "") or (!ereg("^\d{5}$",($_POST["zip_code"]))); { $errors['zip_code']="<font color='red'>*</font>"; ?> But I get this error: Parse error: parse error, unexpected T_LOGICAL_OR in C:\wamp\www\ARB\pio\canada_form.php on line 55 Where am I going wrong? Thanks in advance. SC Quote Link to comment https://forums.phpfreaks.com/topic/45620-solved-form-validation-my-syntax-offbase/ Share on other sites More sharing options...
utexas_pjm Posted April 4, 2007 Share Posted April 4, 2007 <?php if (($_POST["zip_code"] == "") || (!ereg("^\d{5}$",($_POST["zip_code"])))) { $errors['zip_code']="<font color='red'>*</font>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45620-solved-form-validation-my-syntax-offbase/#findComment-221587 Share on other sites More sharing options...
suttercain Posted April 4, 2007 Author Share Posted April 4, 2007 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/45620-solved-form-validation-my-syntax-offbase/#findComment-221593 Share on other sites More sharing options...
suttercain Posted April 5, 2007 Author Share Posted April 5, 2007 Hi guys, I thought I had this but I just "unsolved" the topic. I just tried running the form using the code provided by "utexas_pjm" : if (($_POST["zip_code"] == "") || (!ereg("^\d{5}$",($_POST["zip_code"])))) { $errors['zip_code']="<font color='red'>*</font>"; } Even if I fill out the zip code section of the form with a five digit number it will not process the form. Instead it echos the error "Zip Code*" This is my first time trying to use regex but it appears "^\d{5}$" is right for a zip code. Maybe I have it placed in the form incorrectly? Thanks in advance for any help or suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/45620-solved-form-validation-my-syntax-offbase/#findComment-222258 Share on other sites More sharing options...
suttercain Posted April 5, 2007 Author Share Posted April 5, 2007 I got it: if ($_POST["zip_code"] == "" || !preg_match('/\d{5}/',$_POST["zip_code"])) { $errors['zip_code']="<font color='red'>*</font>"; } Quote Link to comment https://forums.phpfreaks.com/topic/45620-solved-form-validation-my-syntax-offbase/#findComment-222347 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.