These are 2 I uses. one for integer, one for float.
Its triggered on a keypress as the below.  HTH Jeremy




/*
    This function will only allow numeric values to be entered into the calling text form field
*/
function numOnly(evt)
{   
    var charCode = (evt.which) ? evt.which : window.event.keyCode;

    if (charCode <= 13)
    {
        return true;
    }
    else
    {
        var keyChar = String.fromCharCode(charCode);
        var re = /[0-9]/
        return re.test(keyChar);
    }   
}
 
/*
    This function will only allow float values to be entered into the calling text form field
*/
function floatOnly(evt,oControl)
{   
   
    var charCode = (evt.which) ? evt.which : window.event.keyCode;

    if (String.fromCharCode(charCode)==".") //need to check that no other decimal points exist already
        {
            if (oControl.value == "") return false; 
            if (oControl.value.indexOf('.') > 0) return false;
        }

    if (charCode <= 13)
    {
        return true;
    }
    else
    {
        var keyChar = String.fromCharCode(charCode);
        var re = /[0-9.]/
        return re.test(keyChar);
    }   
}

-------- Original Message --------
Subject: [DUG-Offtopic] _javascript_ Numeric Input
From: Neven MacEwan <[EMAIL PROTECTED].nz>
Date: Fri, August 01, 2008 11:19 am
To: NZ Borland Developers Group - Offtopic List
<[EMAIL PROTECTED].nz>

Hi

Can anyone recommend/send me a _javascript_ snippet for a Keyup handler
that restricts to HTML Input to numeric input, with decimal place and
allow negatives

I've searched and cannot find any of suitable usefulness

TIA Neven
_______________________________________________
NZ Borland Developers Group Offtopic mailing list
Post: Offtopic@listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/offtopic
Unsubscribe: send an email to offtopic-request@listserver.123.net.nz with Subject: unsubscribe
_______________________________________________
NZ Borland Developers Group Offtopic mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/offtopic
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe

Reply via email to