Detecting Double Byte Characters
Posted in JavaScript on October 16th, 2004 by kai – Be the first to commentWhile building multi-language content delivery and e-commerce sites, you may run across the need to only allow Roman characters. By using the javascript function below, you can verify the unicode value for each character from some text passed to the function. If the unicode value is greater than 256, then throw an error or deny a form submission.
function isUnicode() {
isTrue=false;
someText = document.form.fieldname.value;
textSize = someText.length;
for (i = 0; i < textSize; i++) {
if (someText.charCodeAt(i) > 256) {
alert("This is not a Roman Character!");
isTrue=true; break;
}
}
return isTrue;
}