How would I use regular expressions to see in a field has been filed with only character a-z, A-Z, or 0-9?

The length does not matter!!

    if (preg_match('/^[a-zA-Z0-9]+$/', $string)) {
        //  Do something
    }
    

    ^ and $ match against the beginning and end of the string, to ensure it only matches if the entire string is valid. [ and ] denote a set of characters, any of which can be matched. + tells it to match one or more of the set, so that it won't accept an empty string, but will accept a string of any length made up of those characters. You can replace + with * (which matches 0 or more characters) in order to allow empty strings to match.

    A regex tutorial and testing tool, for further reading. And of course there's always the manual.

      Have a look at [man]ereg/man and [man]eregi/man

      if (!eregi("[a-z0-9]", $foo)) {
      echo "Fill the form out right, bonehead!";
      } else {
         //process the form
      }

      HTH,

        Write a Reply...