JavaScript regex for alphanumeric string with length of 3-5 chars

前端 未结 3 1027
旧巷少年郎
旧巷少年郎 2020-12-15 17:14

I need regex for validating alphanumeric String with length of 3-5 chars. I tried following regex found from the web, but it didn\'t even catch alphanumerics correctly.

3条回答
  •  一整个雨季
    2020-12-15 17:52

    First this script test the strings N having chars from 3 to 5.

    For multi language (arabic, Ukrainian) you Must use this

    var regex = /^([a-zA-Z0-9_-\u0600-\u065f\u066a-\u06EF\u06fa-\u06ff\ufb8a\u067e\u0686\u06af\u0750-\u077f\ufb50-\ufbc1\ufbd3-\ufd3f\ufd50-\ufd8f\ufd92-\ufdc7\ufe70-\ufefc\uFDF0-\uFDFD]+){3,5}$/;  regex.test('мшефн');
    

    Other wise the below is for English Alphannumeric only

    /^([a-zA-Z0-9_-]){3,5}$/
    

    P.S the above dose not accept special characters

    one final thing the above dose not take space as test it will fail if there is space if you want space then add after the 0-9\s

    \s
    

    And if you want to check lenght of all string add dot .

    var regex = /^([a-zA-Z0-9\s@,!=%$#&_-\u0600-\u065f\u066a-\u06EF\u06fa-\u06ff\ufb8a\u067e\u0686\u06af\u0750-\u077f\ufb50-\ufbc1\ufbd3-\ufd3f\ufd50-\ufd8f\ufd92-\ufdc7\ufe70-\ufefc\uFDF0-\uFDFD]).{1,30}$/;
    

提交回复
热议问题