Page 1 of 1

regex for md5 string

Posted: Mon Aug 29, 2005 11:17 am
by neophyte

Code: Select all

$value = "a8578edf8458ce06fbc5bb76a58c5ca4";
if (preg_match('#\b^[a-z0-9]{32}\b$#', $value )) echo "hello";
I just invented this for check to see if a string is md5 or not. I'm wondering if there is a better way and whether this would be an adequate check.

Posted: Mon Aug 29, 2005 11:22 am
by feyd

Code: Select all

preg_match('#^[a-f0-9]{32}$#i', $text)
is the literal for it.

Posted: Mon Aug 29, 2005 11:28 am
by neophyte
I guess you could also check ctype_xdigit() to make sure it is a hexidecimal number too.