Page 1 of 1

Regex Validation for Textareas

Posted: Thu Aug 31, 2006 11:39 pm
by 1Copenut
Hello:

I'm writing a simple contact script that emails my customer's name, email and message. I'm wanting to use regular expressions to validate their input in the textarea, and am not sure how to write the expression. I want the user to be able to use all letters, numbers and basic punctuation, but nothing else.

I've used basic htmlentities validation in the past, but know there is something better with regexes.

Thank you,

Trevor

Posted: Thu Aug 31, 2006 11:58 pm
by RobertGonzalez
Moved :arrow: to regex.

Re: Regex Validation for Textareas

Posted: Fri Sep 01, 2006 2:04 am
by jmut
1Copenut wrote:Hello:

I'm writing a simple contact script that emails my customer's name, email and message. I'm wanting to use regular expressions to validate their input in the textarea, and am not sure how to write the expression. I want the user to be able to use all letters, numbers and basic punctuation, but nothing else.

I've used basic htmlentities validation in the past, but know there is something better with regexes.

Thank you,

Trevor
htmlentities does not do validation...it is used for escaping (preparing content for use in particular context- in this case html).

You really need regexp.
What do you consider "basic punctuation"?
Can you give us example of names you want to pass and some you don't.

Posted: Fri Sep 01, 2006 2:20 am
by RobertGonzalez
Have you ever used regex before? If so, have you taken a stab at this one yet?

Posted: Fri Sep 01, 2006 5:58 am
by Ollie Saunders

Code: Select all

preg_match('/[:alnum:\s' . preg_quote($puncuationChars) . ']+/i', $subject);