js calculate string length

	var jmz = {};
	jmz.GetLength = function(str) {
		return str.replace(/[\u0391-\uFFE5]/g,"aa").length;
	};

 

For the calculated length, one Chinese character counts as two characters. Example:

 

 

var address = $ ('# address'). val ();
var addrLen = jmz.GetLength(address) / 2;
if(addrLen>25){
    layer.msg('The shipping address cannot exceed 25 characters', {icon:2});
    return false
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326430194&siteId=291194637