Jump to content

Archived

This topic is now archived and is closed to further replies.

mastermike707

Checking form data

Recommended Posts

[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?

Share this post


Link to post
Share on other sites
What kind of output are you seeing?  Do you always get all for errors?

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.