mastermike707 Posted August 3, 2006 Share Posted August 3, 2006 [code]$title = (isset($_POST['title'])) ? strip_tags(htmlentities($_POST['title'])) : false; $err = ($title && preg_match("/[A-Za-z0-9]{3, 50}/", $title)) ? '' : "Your title must be at least three characters long and only letters and numbers.<br />\n"; $author = (isset($_POST['author'])) ? strip_tags(htmlentities($_POST['author'])) : false; $err .= ($author && preg_match("/[A-Za-z0-9]{3, 50}/", $author)) ? '' : "Your name must be at least three characters long and only letters and numbers.<br />\n"; $email = (isset($_POST['email'])) ? strip_tags(htmlentities($_POST['email'])) : false; $err .= ($email && preg_match("/[+]@[+]\.[A-Za-z]{2,3}/", $email)) ? '' :"Your e-mail address must be valid.<br />\n"; $comment = (isset($_POST['comment'])) ? strip_tags(htmlentities($_POST['comment'])) : false; $err .= ($comment && strlen($comment) > 3 && strlen($comment) < 500) ? '' :"You must have at least 3 characters in your comment, but not over 500.<br />\n";[/code]This code never works correctly, even when the values are correct. Any idea why? Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/ Share on other sites More sharing options...
bltesar Posted August 3, 2006 Share Posted August 3, 2006 What kind of output are you seeing? Do you always get all for errors? Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68732 Share on other sites More sharing options...
mastermike707 Posted August 3, 2006 Author Share Posted August 3, 2006 yes all of the error checking messages are outputted. Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68749 Share on other sites More sharing options...
CTM Posted August 3, 2006 Share Posted August 3, 2006 Then either your register_globals is turned off or you're preg_match pattern is incorrect.I checked your pattern, and your error is really...well, stupid.You put :[code]/[A-Za-z0-9]{3, 50}/[/code]Correct one would be :[code]/[A-Za-z0-9]{3,50}/[/code]Notice the lack of space between "3," and "50"? Yup, the space was your error :) Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68752 Share on other sites More sharing options...
mastermike707 Posted August 3, 2006 Author Share Posted August 3, 2006 Wow, ok Thanks a ton.EDIT: I think register_globals is off, how do I fix this? Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68755 Share on other sites More sharing options...
wildteen88 Posted August 3, 2006 Share Posted August 3, 2006 [quote]EDIT: I think register_globals is off, how do I fix this?[/quote]Why do you want to turn it on?Also trunning it on wont change anythink. CTM pointed it out its do with your reqular expressions. Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68756 Share on other sites More sharing options...
mastermike707 Posted August 3, 2006 Author Share Posted August 3, 2006 o ok nvm then, I only am getting the e-mail error now. What is wrong with my e-mail regxp? Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68758 Share on other sites More sharing options...
CTM Posted August 3, 2006 Share Posted August 3, 2006 You're using : /[+]@[+]\.[A-Za-z]{2,3}/To match any character, it's prefer to use (.+?) instead of [+]. You'll also need to put a \ in front of the @ to avoid any warnings, and you'll probably want to change the {2,3} to {2,5}, since some are obviously longer. Also, what about .qc.ca, or any subdomain? Eh?You should use : /(.+?)\@(.+?)\.([a-zA-Z0-9]\.[a-zA-Z0-9]{2,5}|[a-zA-Z0-9]{2,5})/I'm no expert in REGEX though, so it's not optimized. Link to comment https://forums.phpfreaks.com/topic/16475-checking-form-data/#findComment-68777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.