if(preg_match("/^[a-zA-Z0-9]+$/", $str) == 1) {    // string only contain the a to z , A to Z, 0 to 9
}
https://stackoverflow.com/questions/2896450/allow-only-a-za-z0-9-in-string-using-php