Skip to content

Instantly share code, notes, and snippets.

@Tenderfeel
Created July 28, 2017 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tenderfeel/e17bb410c55e0314a704ae2322146759 to your computer and use it in GitHub Desktop.
Save Tenderfeel/e17bb410c55e0314a704ae2322146759 to your computer and use it in GitHub Desktop.
文字数数える
//文字数数える(半角0.5 全角1)
//@param value {string} 数える文字列
function countTxtLength(value) {
var count = 0;
for(var i = value.length; i--; ) {
if(/^[\u0020-\u007e]+$/.test(value.charAt(i))) {
count += 0.5;
} else {
count += 1;
}
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment