validate string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

validate string

Post 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.
waqas_punjabian
Forum Commoner
Posts: 67
Joined: Wed Aug 10, 2005 9:53 am

Re: validate string

Post 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 />";
}
?>
 
Post Reply