0

I am very new to Regular Expressions and I am completely clueless at the moment.

I am trying to create a regular expression in Java that will only allow alphabetical characters. Integers and special characters are not allowed. The minimum length possible is 2 and the maximum length is 10.

TheDetailer
  • 297
  • 4
  • 13
  • 2
    `^[A-Za-z]{2,10}$`... – brso05 Apr 21 '16 at 19:24
  • 1
    In addition to @brso05, use anchors: `^[A-Za-z]{2, 10}$` to **only** allow these characters (otherwise, you might match a substring). [**Without**](https://regex101.com/r/oX6rH5/1) and [**with**](https://regex101.com/r/oX6rH5/2) anchors. – Jan Apr 21 '16 at 19:25

1 Answers1

0

(^[a-zA-Z]{2,10}$) or (\A[a-zA-z]{2,10}\z)

You could also downcase first and make a smaller regex but if that doesn't matter these should work.

myself
  • 425
  • 3
  • 12