• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

ereg code needed..

Ok, here is what I need to do:

The game I play generates a unique ID for each player. This ID is 32 characters long, and contains only numbers 0-9 and letters a-f (I beleive it is an MD5 hash). A common error when entering this ID into forms is they miss letters out or use o's (O) or l's (L) instead of zeros and ones.

The missing letters is easy (strlen), but what about each letter/number? I realise I could loop through each letter/number and check it's ASCII code is within the two ranges, but is there some snazzy ereg code I can use? Or would the loop be better?

Thanks!
0
rjdown
Asked:
rjdown
  • 2
1 Solution
 
keteracelCommented:
if (preg_match("/$[0-9a-f]{32}^/", $str)) {
  echo "correct";
}
0
 
keteracelCommented:
oops, this one works!

<?php

$str = "1234567890abcefdac127dce4638ae22";

if (preg_match("/^[0-9a-f]{32}$/", $str)) {
  echo "correct";
}
else {
  echo "incorrect";
}

?>
0
 
rjdownAuthor Commented:
Great stuff, thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now