Page 1 of 1

Validating a textarea

Posted: Sat Jul 10, 2010 1:53 am
by nithinkk
<form id="form1" name="form1" method="post" action="thanks.php">
<label for="text"></label>
<textarea name="text" id="text" cols="87" rows="9"></textarea>
<br/> <br/><br/><input type="submit" name="submit" id="go" value="Submit" />
</form>


This is my form, i want to validate the textarea : only letters, space and numbers allowed. i want to avoid "+-*()?|/\"

can any one help me ? i want to validate with php ....

Re: Validating a textarea

Posted: Sat Jul 10, 2010 2:36 am
by nithinkk
i got it from a book :-)

we can check it with regular expressions


# string validation
ereg(“[^-’A-Za-z0-9 \t]”, “don’t forget about secu-rity”); // Boolean(false)

Re: Validating a textarea

Posted: Sat Jul 10, 2010 2:55 am
by requinix
Don't use ereg.

Code: Select all

preg_match('/[^a-z0-9\s]/i', $text) // should be false

Re: Validating a textarea

Posted: Sat Jul 10, 2010 7:14 am
by nithinkk
ereg(“[^-’A-Za-z0-9 \t]”, “don’t forget about secu-rity”); // Boolean(false)
preg_match('/[^a-z0-9\s]/i', $text) // should be false


What is the difference between ereg and preg_match ????? and why u said Don't use ereg ???

Re: Validating a textarea

Posted: Sat Jul 10, 2010 9:57 am
by AbraCadaver
nithinkk wrote:ereg(“[^-’A-Za-z0-9 \t]”, “don’t forget about secu-rity”); // Boolean(false)
preg_match('/[^a-z0-9\s]/i', $text) // should be false


What is the difference between ereg and preg_match ????? and why u said Don't use ereg ???
http://us3.php.net/manual/en/function.ereg.php: You see the big warning in red?

Re: Validating a textarea

Posted: Sun Jul 11, 2010 11:39 pm
by nithinkk
thanks :-)