Jump to content


Photo

ereg, preg_match... none work for me :(


  • Please log in to reply
3 replies to this topic

#1 golyath

golyath
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 01:35 AM

All i want to do is check the $data variable is in the correct format (i.e 99-aa-00 9999:99)

I have tried to get these to work for me but none seem to. I have put the regex through a regex checker and it works...

i have this:

<?php
$data = "99-aa-00 9999:99";
$result=preg_match("/^[0-9]{2}-[a-Z]{2}-[0-9]{3}\s[0-9]{4}:[0-9]{2}$/", $data);
if($result != "0"){
echo "correct";
}
else{
echo "wrong";
}
?>


but it always returns this error:

Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 13

can anyone tell me what im doing wrong.

thank you for any help, its muchley appreciated

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 19 September 2006 - 01:36 AM

Try [a-zA-Z] instead of [a-Z].. or [[:alpha:]]

#3 golyath

golyath
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 September 2006 - 01:40 AM

Cheers,

I ahve tried both and they both stop the error coming up... but it returns "wrong" but it should return correct. Have structured the statement correctly?

thanks

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 19 September 2006 - 01:54 AM

You are looking for 3 digits before the space--it should be 2.

<pre>
<?php
   $data = '99-aa-00 9999:99';
   echo preg_match('/^\d{2}-[A-Za-z]{2}-\d{2}\s\d{4}:\d{2}$/', $data) ?
		'correct' :
		'wrong' ;
?>
</pre>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users