-2

I would like to check if there is any occurrence of an uppercase or lowercase string in this:

test strings

1a
2A
3aC

js

const str = '1a'
/[a-z]/.test(str) //Pass
/[a-z][A-Z]/.test(str) //Fail
/[a-z]/.test(str) //Pass
sshashank124
  • 31,495
  • 9
  • 67
  • 76
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291

2 Answers2

1

Unless there are some edge cases you are worried about....

[a-zA-Z]

should work

ruskibenya
  • 19
  • 4
1

[a-z] means 1 lowercase letter. [A-Z] means 1 uppercase letter. [a-z][A-Z] means 1 lowercase letter followed by 1 uppercase letter. [a-zA-Z] means 1 lowercase or uppercase letter.

To check for "3aC" you might want [0-9][a-zA-Z]+. The "+ means one or more lowercase or uppercase letters.

Fred
  • 12,086
  • 7
  • 60
  • 83