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 21st, 2007
hi...i want to use the preg match function to verify a string that should have the format format of a year - two digits - two letters - two digits, like this: [in]2005-03-IT-031[/in] thanks
baba
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 36
Reputation: azimuth0 is an unknown quantity at this point 
Solved Threads: 5
azimuth0 azimuth0 is offline Offline
Light Poster

Re: help with preg match

 
0
  #2
May 22nd, 2007
Ok, so what is the question?
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
  #3
May 22nd, 2007
  1. <?php
  2. $string = '2005-03-IT-31';
  3. if (preg_match ('/^[\d]{4}-[\d]{2}-[a-z]{2}-[\d]{2}$/i',$string)) {
  4. echo "Right format";
  5. }
  6. else {
  7. echo "Wrong format";
  8. }
  9.  
  10. ?>
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 36
Reputation: azimuth0 is an unknown quantity at this point 
Solved Threads: 5
azimuth0 azimuth0 is offline Offline
Light Poster

Re: help with preg match

 
0
  #4
May 22nd, 2007
That won't work, unless I'm reading it wrong...

  1. <?php
  2. $string = '2005-03-IT-31';
  3. if (preg_match('/^\\d{4}-\\d{2}-[a-z]{2}-\\d{2}$/i',$string)) {
  4. echo "Right format";
  5. } else {
  6. echo "Wrong format";
  7. }
  8. ?>
Last edited by azimuth0; May 22nd, 2007 at 6:19 pm. Reason: odd tag showed up?
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
  #5
May 22nd, 2007
The way I wrote it
  1. ... [\d]{4}...
, it works.
The way you wrote it
  1. ... \\d{4} ...
, it doesn't.
Last edited by johny_d; May 22nd, 2007 at 7:25 pm.
Reply With Quote Quick reply to this message  
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

Re: help with preg match

 
0
  #6
May 24th, 2007
that worked, thanks alot...
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
  #7
May 24th, 2007
You're welcome
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


Views: 3820 | Replies: 6
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC