1

I want check if text contain cyrillic characters and if contain set max length for field max 60 characters else set max length 170 characters. I tried next code:

var _this = this;
    var value = el.getValue();
    if (value.match(/[^а-яА-ЯёЁ\n0-9,.!():;@&#%+_/\'\" -]/ig) === null) {
        _this.getViewModel().set('myMaxLength', 60);
        _this.getViewModel().set('length', value.length);
    } else if (value.match(/[^a-zA-Z\n0-9,.!():;@&#%+_/\'\" -]/ig) === null) {
        _this.getViewModel().set('myMaxLength', 170);
        _this.getViewModel().set('length', value.length);
    } else {
        _this.getViewModel().set('myMaxLength', 60);
        _this.getViewModel().set('length', value.length);
    }

My code not work correctly, because when text on France max length sets 60 characters, but need 170. How I can allow all character except cyrillic.

Andriy Yushko
  • 395
  • 5
  • 21
  • There might be multiple ways. But I am unaware of any keystroke definition for these. (since I never encounter these in my daily life.) One of them is hardcoding the characters in. So create an array where you type every single character. Then loop through the array whilst comparing to your input. – Sparky Sep 19 '18 at 12:21
  • Possible duplicate of [How to match Cyrillic characters with a regular expression](https://stackoverflow.com/questions/1716609/how-to-match-cyrillic-characters-with-a-regular-expression) – Mark Baijens Sep 19 '18 at 12:25

1 Answers1

0

I replace my regex on /[^\u0000-\u007f]/ and it solve my problem. Also i change condition:

if (value.match(/[^\u0000-\u007f]/)) {
        _this.getViewModel().set('myMaxLength', 60);
        _this.getViewModel().set('length', value.length);
    } else {
        _this.getViewModel().set('myMaxLength', 170);
        _this.getViewModel().set('length', value.length);
    }
Andriy Yushko
  • 395
  • 5
  • 21