preg_match

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
theS70RM
Forum Newbie
Posts: 2
Joined: Wed Sep 23, 2009 9:19 am

preg_match

Post by theS70RM »

Hey guys,

im having a bit of trouble creating a regular expression to validate objectguid's.

They must be no more or less than 32 characters in length, and case insensitive HEX characters, ie a-z A-Z 0-9
here's the function im using but it's not right

Code: Select all

 
    function isGuid($guid){
 
        //doesnt work correctly
        return preg_match( '/[a-fA-F0-9]{32,32}/', $guid);
        
    }
 
 

this is valid:
"ca9bc7b5ff1a3345b3d8c5e09316015e"



Can anyone help me get the correct regular expression.

Thanks


Andy
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: preg_match

Post by Mark Baker »

Start and end markers

Code: Select all

 
function isGuid($guid){
    //works correctly
    return preg_match( '/^[A-F0-9]{32}$/i', $guid);
}
 
theS70RM
Forum Newbie
Posts: 2
Joined: Wed Sep 23, 2009 9:19 am

Re: preg_match

Post by theS70RM »

ah knew it would be something stupid.

Thanks very much =)
Post Reply