JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="myinput"></textarea>
<div id="charcount"></div>
CSS
textarea {
width:400px;
height:100px;
}
JavaScript
var charCount = $('#charcount');
$('#myinput').keyup(function () {
var text = this.value;
var isChinese = /[\u4E00-\u9FFF\u6300-\u77FF\u7800-\u8CFF\u8D00-\u9FFF]+/.test(text);
if (!isChinese && (/[^\x00-\x80]+/.test(text))) {
charCount.text("Error: Neither ASCII nor Chinese Unicode Character Entered");
return;
}
var credits = {chinese: [
[1,60],
[60,130],
[130,190]
],english: [
[1,152],
[152,298],
[298,450],
[450,596],
[602,754]
]};
var _credits = credits[isChinese?"chinese":"english"];
var i;
for (i = _credits.length; i > 1; i--) {
if (text.length >= _credits[i-1][0] && text.length < _credits[i-1][1]) break;
}
charCount.text('We will deduct '+ i +' credit for this message per contact. Characters: '+text.length);
});