ereg code needed..

Posted on 2005-05-17
Last Modified: 2012-05-05
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?

Question by:rjdown
    LVL 9

    Expert Comment

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

    Accepted Solution

    oops, this one works!


    $str = "1234567890abcefdac127dce4638ae22";

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

    LVL 6

    Author Comment

    Great stuff, thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now