javascriptregexxregexp

RegExp for Cyrillic+minimum 3 letters+without numbers and space+non repeatable at the end


I do have the following RegExp in the current web application.

function myCyrillicValidator(text){
    return XRegExp("^\\p{Cyrillic}+$").test(text);
}

As you can see I use XRegExp javasciprt library. Currently, this regxep checks if its cyrillic. I want to extend it and to check:

I tried few online RegExp tester/builders to build on top of the current rule. But none of them showed me that the current regexp is working correctly. But surprisingly, its working in the webapp, but not in the online testers.

XregxExp version is 2.0.0 if it does matter


Solution

  • Use the following regex:

    XRegExp("^(?=\\p{Lu})(?!.*(.)\\1$)\\p{Cyrillic}{3,}$")
    

    See the regex demo.

    Details:

    function myCyrillicValidator(text){
        return XRegExp("^(?=\\p{Lu})(?!.*(.)\\1$)\\p{Cyrillic}{3,}$").test(text);
    }
    
    console.log(myCyrillicValidator("Ва"));    // => false 
    console.log(myCyrillicValidator("вася"));  // => false
    console.log(myCyrillicValidator("Васяя")); // => false
    console.log(myCyrillicValidator("Вася"));  // => true
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xregexp/2.0.0/xregexp-all-min.js"></script>