Angular Validation: Input should either contain Latin or Georgian characters, but not both of them together

Viewed 273

This is my template for this part, but it doesn't seem to work.

(('^[\u10D0-\u10F0]+$')||('^[a-zA-Z]+$'))&&!(('^[\u10D0-\u10F0]+$')&&('^[a-zA-Z]+$'))

Also, it shouldn't contain any other characters or numbers, just Georgian or Latin.

1 Answers

You can use

Validators.pattern(/^([a-zA-Z]+|[\u10D0-\u10F0]+)$/)
Validators.pattern('([a-zA-Z]+|[\\u10D0-\\u10F0]+)')

In the second line of code, as the regex is set with a string literal, ^ and $ are added by Angular automatically.

Details:

  • ^ - start of string
  • ([a-zA-Z]+|[\u10D0-\u10F0]+) - Group 1 matching either one or more ASCII letters or one or more chars matched with \u10D0-\u10F0 range (Gergian letters from ა to ჰ)
  • $ - end of string.
Related