-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
  • 29,826
  • 8
  • 62
  • 75
Jamie Hutber
  • 24,715
  • 40
  • 159
  • 259

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
  • 11,252
  • 4
  • 54
  • 71