help with preg match

Reply

Join Date: Apr 2007
Posts: 33
Reputation: realnsleo is an unknown quantity at this point 
Solved Threads: 0
realnsleo realnsleo is offline Offline
Light Poster

help with preg match

 
0
  #1
May 24th, 2007
hi there,
how do i validate names like surname and first name with the preg_match function???
baba
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 68
Reputation: johny_d is an unknown quantity at this point 
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: help with preg match

 
0
  #2
May 24th, 2007
Depends on how you think your users first name and surname would be.
For example, let's say the first name would be a single word, 4 to 20 letters and surname would be one or two words, each between 3 to 20 letters.
You would have something like this:
  1. <?php
  2. $name = 'Jackson';
  3. $surname = 'George Michael';
  4. if (preg_match ('/^[a-z]{4,20}$/i',$name)) {
  5. echo "Good name";
  6. }
  7. else {
  8. echo "Bad name";
  9. }
  10.  
  11. if (preg_match ('/^[a-z]{3,20}(| [a-z]{3,20})$/i',$surname)) {
  12. echo "Good surname";
  13. }
  14. else {
  15. echo "Bad surname";
  16. }
  17.  
  18. ?>
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC