Question : Is there a way for Javascript to detect what characters are being used in a form?

Can javascript detect if form input is non-Roman characters? ie, Japanese characters?

Answer : Is there a way for Javascript to detect what characters are being used in a form?

You can detect the character keycode value using javascript so if any keycode denotes a non-roman character then you can validate it. I am not sure of any other way.

i have below a keypress function which detects the keycode of the key that is pressed on the keyboard and validates for a Decimal value only. You could probably modify this to suite your needs.

function KeyPress(e)
{
    var iKeyCode;
    if (!e) {
    var e = window.event;
    }

    if (e.keyCode) {
        iKeyCode = e.keyCode;
        } else {
        if (e.which) {
          iKeyCode = e.which;
        }
    }
       
    switch(iKeyCode) {
        case 8:
        case 9:
        case 37:
        case 38:
        case 39:
        case 40:
        case 46:
              break;
        case 48:
        case 49:
        case 50:
        case 51:
        case 52:
        case 53:
        case 54:
        case 55:
        case 56:
        case 57:

        case 96:
        case 97:
        case 98:
        case 99:
        case 100:
        case 101:
        case 102:
        case 103:
        case 104:
        case 105:
              //return correct numeric from keypad
              return iKeyCode - 48; break;      

      
        default: return false;
    }
}

Random Solutions  
 
programming4us programming4us