Having trouble with my form validation

Reply

Join Date: Aug 2007
Posts: 3
Reputation: wireshop is an unknown quantity at this point 
Solved Threads: 0
wireshop wireshop is offline Offline
Newbie Poster

Having trouble with my form validation

 
0
  #1
Aug 2nd, 2007
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:
  1. if(!preg_match("/[^a-zA-Z0-9\.\-¤œ¼\ ]+$/",$name)||empty($name))
  2. {
  3. print '<td colspan="2" class="ErrorText"><div align="right">Please enter a valid name without special characters i.e. *,/,&lt; etc. </div></td>';
  4. $error++;
  5. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 7
Reputation: nanharb is an unknown quantity at this point 
Solved Threads: 0
nanharb nanharb is offline Offline
Newbie Poster

Re: Having trouble with my form validation

 
0
  #2
Aug 3rd, 2007
I don't use preg_match, but this code works for me to make sure users only use numbers and letters.
  1. if (eregi ("^[[:alnum:]]+$", $_POST['username'])) {
  2. $a = TRUE;
  3. } else {
  4. $a = FALSE;
  5. $message[] = "Please enter a username that consists only of letters and numbers.";
  6.  
  7. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 42
Reputation: cereal is an unknown quantity at this point 
Solved Threads: 4
cereal cereal is offline Offline
Light Poster

Re: Having trouble with my form validation

 
0
  #3
Aug 3rd, 2007
You can also use ctype_alnum, this way:

  1. $username = ctype_alnum($_POST['username']) ? $_POST['username'] : NULL;
  2.  
  3. if($username == NULL) {
  4. echo 'error message';
  5. } else {
  6. echo $username;
  7. }
Last edited by cereal; Aug 3rd, 2007 at 9:13 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC