Created
July 28, 2017 03:39
-
-
Save Tenderfeel/e17bb410c55e0314a704ae2322146759 to your computer and use it in GitHub Desktop.
文字数数える
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//文字数数える(半角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