Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
-
neophyte
- DevNet Resident
- Posts: 1537
- Joined: Tue Jan 20, 2004 4:58 pm
- Location: Minnesota
Post
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.
-
feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Post
by feyd »
Code: Select all
preg_match('#^[a-f0-9]{32}$#i', $text)
is the literal for it.
-
neophyte
- DevNet Resident
- Posts: 1537
- Joined: Tue Jan 20, 2004 4:58 pm
- Location: Minnesota
Post
by neophyte »
I guess you could also check ctype_xdigit() to make sure it is a hexidecimal number too.