javascript good chars

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function getkey(e) {
        if (window.event)
                return window.event.keyCode;
        else if (e)
                return e.which;
        else
                return null;
} // end getkey
 
function goodchars(e, goods) {
        // < input name="example" onkeypress="return goodchars(event,'0123456789')" >
        var key, keychar;
        key = getkey(e);
        if (key == null) return true;
        keychar = String.fromCharCode(key);
        keychar = keychar.toLowerCase();
        goods = goods.toLowerCase();
        if (goods.indexOf(keychar) != -1)
                return true;
        if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
                return true;
        return false;
} // end goodchars