2

I actually got this regex ^[A-zÀ-ÿ ]{3,50}$ or ^[A-zÀ-ÿ\s]{3,50}$ that finds 3 to 50 characters of this specific alphabets. I need a new regex to accept only 1 whitespace character \s maintaining the {3,50} limitation.

I tried ^[A-zÀ-ÿ]+\s[A-zÀ-ÿ]{3,50}$ but it is limiting the last tuple to 3-50 and not the whole thing.

Any help would be appreciated, Thank you

Fábio Silva
  • 129
  • 2
  • 14

1 Answers1

4

Actually, to match ASCII letters, you need to use [A-Za-z], not [A-z] (see this SO thread).

As for the single obligatory whitespace, it can be added as in your attempt, and the length limitation can be added in the form of a lookahead:

/^(?=.{3,50}$)[A-Za-zÀ-ÿ]+\s[A-Za-zÀ-ÿ]+$/
  ^^^^^^^^^^^^ 

See the regex demo.

Community
  • 1
  • 1
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    I found that accent expression here http://stackoverflow.com/questions/20690499/concrete-javascript-regex-for-accented-characters-diacritics/26900132#26900132 Anyways thanks, your expression is doing what I want. – Fábio Silva Jan 16 '17 at 10:11