| | |
Having trouble with my form validation
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
I'm having a trouble getting my php script to validate user input what am I doing wrong here? This just displays the error message all the time.
for example:
for example:
PHP Syntax (Toggle Plain Text)
if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\ ]+$/",$name)||empty($name)) { print '<td colspan="2" class="ErrorText"><div align="right">Please enter a valid name without special characters i.e. *,/,< etc. </div></td>'; $error++; }
•
•
Join Date: Jul 2007
Posts: 7
Reputation:
Solved Threads: 0
I don't use preg_match, but this code works for me to make sure users only use numbers and letters.
PHP Syntax (Toggle Plain Text)
if (eregi ("^[[:alnum:]]+$", $_POST['username'])) { $a = TRUE; } else { $a = FALSE; $message[] = "Please enter a username that consists only of letters and numbers."; }
•
•
Join Date: Aug 2007
Posts: 42
Reputation:
Solved Threads: 4
You can also use ctype_alnum, this way:
PHP Syntax (Toggle Plain Text)
$username = ctype_alnum($_POST['username']) ? $_POST['username'] : NULL; if($username == NULL) { echo 'error message'; } else { echo $username; }
Last edited by cereal; Aug 3rd, 2007 at 9:13 am.
![]() |
Similar Threads
- PHP: Form Validation (PHP)
- PHP Form Validation ??? (PHP)
- Simple JavavScript needs email validation (JavaScript / DHTML / AJAX)
- .net validation/javascript conflict (ASP.NET)
- owner form display problem (VB.NET)
- help with form/ display issues (ColdFusion)
- Problems in Dynaform (Form Mail) URGENT HELP (PHP)
- form validation not working (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: Need information about Rand()
- Next Thread: prevent scraping
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube





