JavaScript: check if a giving string contains only letters or digits
Using regexp, you can add 0-9
to say any digit between 0 and 9:
boolean onlyLettersAndDigits(String str) {
return str.matches("^[a-zA-Z0-9]+$");
}
Add 0-9 also to your regex
boolean onlyLetters(String str) {
return str.match("^[A-Za-z0-9]+$");
}