Search code examples
cssmobile-website

Force numeric input for mobile website


I've been using the '-wap-input-format' CSS property to force to numeric input using "*N". 307This works on my SonyEricsson C702, but fails on Windows Mobile IE, Windows Mobile with Opera or SonyEricsson P1i.


Solution

  • My suggestion is also to add some Javascript. Mobile Opera as well as the iPhone, Minimo (mini-mozilla) and more can understand Javascript, at least to some extent.

    function noNumbers(e) {
        var keynum;
        var keychar;
        var numcheck;    
        if(window.event) // IE
        {
            keynum = e.keyCode;
        }
        else if(e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which;
        }
    
        if((keynum >= 48) && (keynum <= 57)) {
            return(true);
        }
    
        var good_codes = [8, 14, 15, 37, 38, 39, 40];
        for(i = 0; i < good_codes.length; i++) {
            if(good_codes[i] == keynum) {
                return(true);
            }
        }
    
        return(false);
    }
    

    Hope this helps! : )

    metafilter.com