inicio mail me! sindicaci;ón

Archive for October, 2004

Detecting Double Byte Characters

While 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;
}