Validating a textarea

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nithinkk
Forum Commoner
Posts: 55
Joined: Sat Nov 28, 2009 7:57 am

Validating a textarea

Post 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 ....
nithinkk
Forum Commoner
Posts: 55
Joined: Sat Nov 28, 2009 7:57 am

Re: Validating a textarea

Post 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)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Validating a textarea

Post by requinix »

Don't use ereg.

Code: Select all

preg_match('/[^a-z0-9\s]/i', $text) // should be false
nithinkk
Forum Commoner
Posts: 55
Joined: Sat Nov 28, 2009 7:57 am

Re: Validating a textarea

Post 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 ???
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Validating a textarea

Post 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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
nithinkk
Forum Commoner
Posts: 55
Joined: Sat Nov 28, 2009 7:57 am

Re: Validating a textarea

Post by nithinkk »

thanks :-)
Post Reply