I need a help with regex which checks the string contains only letter and numbers but not only numbers
Valid
* letters
* 1wret
* 0123chars
* chars0123
*
Instead of using a regular expression, you can also use the ctype_*()
functions:
var_dump(ctype_alnum('letters') && !ctype_digit('letters')); // bool(true)
var_dump(ctype_alnum('0123chars') && !ctype_digit('0123chars')); // bool(true)
var_dump(ctype_alnum('1324') && !ctype_digit('1324')); // bool(false)
var_dump(ctype_alnum('xcvxxc%$#') && !ctype_digit('xcvxxc%$#')); // bool(false)
But if you want a regular expression, you can use this:
var_dump(preg_match('/^[a-z0-9]*[a-z]+[a-z0-9]*$/i', $input));