rickphp Posted January 6, 2010 Share Posted January 6, 2010 I need it so that if the email field isn't blank then the validation be ran against it, but the form is sending even when the message is left empty even though the validation in place is correct, I think the way the below is coded is causing the issue, can it be improved? Here is the current code I've got: else if ($email != "") { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $error = "The format of your email address is not valid."; } } Sorry if thats not clear enough but hopefully you get what I mean! Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/187463-form-validation-problem/ Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 Without looking at the regexp extensively, where is $email being assigned? Maybe the issue lies there rather than at this particular bit of code. I'm not fantastic with regexp, but this looks passable as email validation code (though I do have this feeling that something isn't quite right, but I can't put my finger on it). Link to comment https://forums.phpfreaks.com/topic/187463-form-validation-problem/#findComment-989859 Share on other sites More sharing options...
rickphp Posted January 6, 2010 Author Share Posted January 6, 2010 $email is inputted via a form, I think its this bit of coding thats causing the problem as when I remove this bit of code the problem goes away, but I need to ensure proper emails are entered. Any ideas? The form consists of name, businessname, email, phonenumber and message, the problem arrises when the person fills out their email, they can leave the message field empty and the form still sends, if they dont enter an email and only enter a phone number (which is acceptable) they then need to enter a message before the form sends (which again is correct) but its only when entering an email the rest of the validation following the code provided stops working. I think the way I've coded it is halting any following validation.. but only when an email is inputted Link to comment https://forums.phpfreaks.com/topic/187463-form-validation-problem/#findComment-989863 Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 Is it possible for you to provide the code for the entire page so we can take a look? Link to comment https://forums.phpfreaks.com/topic/187463-form-validation-problem/#findComment-989877 Share on other sites More sharing options...
rickphp Posted January 6, 2010 Author Share Posted January 6, 2010 Is it possible for you to provide the code for the entire page so we can take a look? I've PM'd you. Link to comment https://forums.phpfreaks.com/topic/187463-form-validation-problem/#findComment-989922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.