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

Ok, so what is the question?

<?php
$string = '2005-03-IT-31';
if (preg_match ('/^[\d]{4}-[\d]{2}-[a-z]{2}-[\d]{2}$/i',$string)) {
 echo "Right format";
 }
else {
 echo "Wrong format";
 }
 
?>

That won't work, unless I'm reading it wrong...

<?php
$string = '2005-03-IT-31';
if (preg_match('/^\\d{4}-\\d{2}-[a-z]{2}-\\d{2}$/i',$string)) {
  echo "Right format";
} else {
  echo "Wrong format";
}
?>

The way I wrote it

... [\d]{4}...

, it works.
The way you wrote it

... \\d{4} ...

, it doesn't.

that worked, thanks alot...

You're welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.