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.