-1

Using regex, I'm trying to check whether there's only 2-4 characters used after a .. At the moment, i got it working to detect when its less than 2 characters but after 4 characters, it still deems it as successful. How can I fix this? This is what I have written down:

/.[a-zA-Z]{2,4}$/
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

2 Answers2

0

You need to escape the dot (.).

/\.[a-zA-Z]{2,4}$/
plalx
  • 42,889
  • 6
  • 74
  • 90
-1

. is the control character in RegExp, you should to escape it:

/\.[a-zA-Z]{2,4}$/

And, to ignore case, add the i flag:

/\.[a-z]{2,4}$/i
devdb
  • 49
  • 3