简体   繁体   中英

Adding regex for only Cyrillic letters and white spaces

I have read this and many other posts, questions and articles, but whaterver I do I cannot make the validation for only-cyrillic works.

Here is my validation check:

$.validator.addMethod("onlycyrillic", function (value, element, param) {
    var inputValue = $.trim(value);
    var cyrillicValidationRegex = RegExp("/[\wа-я]+/s+/ig");
    var testResult = cyrillicValidationRegex.test(inputValue);
    return testResult;
});

To validate a string only consisting of Cyrillic letters and whitespace chars you may use

/^[\u0400-\u0484\u0487-\u052F\u1C80-\u1C88\u1D2B\u1D78\u2DE0-\u2DFF\uA640-\uA69F\uFE2E\uFE2F\s]*$/

Details

  • ^ - start of string
  • [\Ѐ-\҄\҇-\ԯ\ᲀ-\ᲈ\ᴫ\ᵸ\ⷠ-\ⷿ\Ꙁ-\ꚟ\︮\︯\\s]* - 0 or more Cyrillic letters or whitespaces (see the chars included here )
  • $ - end of string.

JS test:

 var s = "Меня зовут Витя"; var cyrillicValidationRegex = /^[\Ѐ-\҄\҇-\ԯ\ᲀ-\ᲈ\ᴫ\ᵸ\ⷠ-\ⷿ\Ꙁ-\ꚟ\︮\︯\\s]*$/; console.log(cyrillicValidationRegex.test(s)); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM