Link to home
Start Free TrialLog in
Avatar of VD1234
VD1234

asked on

RegularExpressionvalidator Validor for a numeric entry in a textbox

I have a textbox for which I allow only integers. How can I define a regularexpressionvalidator for this requirement.

Please help.
Thanks in advance.
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

try this  and attach the function to the textfield

function restrictChars(e) {
        var intKey;
        var restrictedKeys = new Array();
        
        //Set your restricted keyCodes from the URL I gave you
        restrictedKeys[0] = 8
        restrictedKeys[1] = 20
 
        if(window.Event)
            intKey = e.which;
        else
            intKey = e.KeyCode;
 
        for(var i = 0; i < restrictedKeys.length; i++) {
            if(intKey == restrictedKeys[i])
                e.returnValue = false;
            else {
                // Here is a sample check for numerics
                if(intKey > 47 && intKey < 58) {
                    // They pressed a number;
                    e.returnValue = false;
                }
            }
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sinoj Sebastian
Sinoj Sebastian
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial