Another solution: [code]function validate($str, $mask) { $validlength=10; $str=strtolower($str); if (strspn($str, $mask) == strlen($str) && $validlength >= strlen($str)) { return true; } else { return false; } } $str = "test"; $mask = "abcdefghijklmnopqrstuvwxyz"; validate($str,$mask);[/code] The $mask string contains all of the valid characters, so you could easily change it to 0123456789 to cover a form input meant only for numbers. This was taken from PHP.net a long time ago, but I can't remember the author's name to give proper credit :\