Jump to content


Photo

Checking form data


  • Please log in to reply
7 replies to this topic

#1 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 August 2006 - 05:54 PM

$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";
This code never works correctly, even when the values are correct. Any idea why?
[url=http://www.mastermike707.com/new/][/url]

#2 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 03 August 2006 - 06:02 PM

What kind of output are you seeing?  Do you always get all for errors?

#3 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 August 2006 - 06:20 PM

yes all of the error checking messages are outputted.
[url=http://www.mastermike707.com/new/][/url]

#4 CTM

CTM
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 03 August 2006 - 06:24 PM

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 :

/[A-Za-z0-9]{3, 50}/

Correct one would be :

/[A-Za-z0-9]{3,50}/

Notice the lack of space between "3," and "50"? Yup, the space was your error :)

#5 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 August 2006 - 06:29 PM

Wow, ok Thanks a ton.

EDIT: I think register_globals is off, how do I fix this?
[url=http://www.mastermike707.com/new/][/url]

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 August 2006 - 06:32 PM

EDIT: I think register_globals is off, how do I fix this?

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.

#7 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 August 2006 - 06:34 PM

o ok nvm then, I only am getting the e-mail error now. What is wrong with my e-mail regxp?

[url=http://www.mastermike707.com/new/][/url]

#8 CTM

CTM
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 03 August 2006 - 07:21 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users