Search code examples
javascriptangularjsregexvalidationangularjs-ng-pattern

Regex acts weird


I want to create a regex expression that I can pass to ng-pattern so that the input can only be valid if the string has only uppercase/lowercase latin letters from a to z, n with tilde, and vowels with acute accents; as well as dot. I came up with what I thought was the solution, but angularjs keeps telling me in the developer tools that my string is not valid when string is:

  • ñ, Ñ
  • á, e, í, ó, ú—also in uppercase
  • a dot followed by a dot followed by a space—not that I am really interested in having that, but I think it should be valid.

This is what I've got : "[A-Za-z\.\s\U+00C1\U+00C9\U+00CD\U+00D1\U+00D3\U+00DA\U+00E1\U+00E9\U+00ED\U+00F1\U+00F3\U+00FA]+"

What am I doing wrong?

P.S. I tried the | operator mentioned in the wiki for the [Jun|Jul|Aug] example, but it acts even weirder.


Solution

  • This regex should work for your needs:

    [A-Za-z\.\s\u00C1\u00C9\u00CD\u00D1\u00D3\u00DA\u00E1\u00E9\u00ED\u00F1\u00F3\u00FA]+