Page 1 of 1

validate string

Posted: Sat Nov 15, 2008 7:10 am
by bouncer
hi there.

anyone can tell how can i validate a string like this one "EA786447551PT" using the preg_match() function, the string have 13 characters, the first two are alphanumeric and the last two the same, and only alpha and numeric are allowed.

can you give me some help with this ? :roll:

thanks in advance.

Re: validate string

Posted: Sat Nov 15, 2008 7:54 am
by waqas_punjabian
Try this:

Code: Select all

 
<?php
if (preg_match("/^[a-zA-Z0-9]{2}[0-9]{9}PT$/", "EA786447551PT", $matches)) {
  echo "Match was found <br />";
  echo $matches[0];
}else{
  echo "Match was not found <br />";
}
?>