How to write such a regular expression?

allows you to enter Chinese, English, numbers, symbols, etc., limited to 50 or 100 characters

Aug.23,2021

what are you not allowed to enter? Is there anything that is not allowed?
is there only a limit on the length of Chinese characters and letters?

A regular matching of numbers will achieve your effect. / [^\ X00 -\ xff] / g you have to consider that if there are letters and numbers at the same time
to match each character of the value cycle if is in Chinese, then sum+2 if sum 100, then do your operation

.

first encapsulate a function for judging the length of double-byte characters:
(the reason why the function is used to match double-byte characters is to use the charCodeAt method, double-byte character rules cannot be completely matched, and there are too many characters in the world)

String.prototype.dbLength = function() {
    'use strict';
    //
    var str = this;
    var leg = str.length;
    for (var i in str) {
        if (str.hasOwnProperty(i)) {
            var s = str[i];
            //Unicode ,16
            var db = s.charCodeAt(0).toString(16).length == 4;
            if (db) leg += 1;
        }
    }
    return leg;
};

then start regular matching:

function check(str){
    if(typeof str!=='string'|| str.dbLength()<50||str.dbLength()>100){ return false;}
    return /[a-z0-9\!@-sharp\$\%\^&\*\(\)_+=\-,;\.\/\?'"\\\|]/i.test(str)
}

Test call:

check('123abc,.\/')
Menu