I need a help with regex which checks the string contains only letter and numbers but not only numbers
Valid
* letters
* 1wret
* 0123chars
* chars0123
*
Here are the components of the regex we're going to use:
^ and $ are the beginning and end of the string anchors respectively\d matches a digit[a-zA-Z] matches a letter[a-zA-Z\d] matches a letter or a digit* is "zero-or-more" repetitionWith these, we can now compose the regex we need (see on rubular.com):
^\d*[a-zA-Z][a-zA-Z\d]*$
Here's an explanation of the pattern:
from the beginning... till the end
| |
^\d*[a-zA-Z][a-zA-Z\d]*$
\_/\______/\_________/
The 3 parts are: