Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validate number to be numeric
Message
From
30/04/2009 15:40:01
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
General information
Forum:
Internet
Category:
Javascript
Miscellaneous
Thread ID:
01397260
Message ID:
01397320
Views:
27
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi everybody,
>>>
>>>I have a JavaScript to ValidateDate (called ValidateDate). This script is attributed to Einar Kvandahl. I need a similar script to validate number (should only allow integer positive numbers). Is there something built in?
>>>
>>>Thanks in advance.
>>
>>I hit up google and found http://acmesoffware.com/acme/ExamplesJS/jsExm_ValidateInteger.asp. Please let me know if you find one that works well because I'm sure I will eventually need one.
>
>I can not yet make it work. Here is the page and the function
>
>http://forums.asp.net/p/1417609/3131496.aspx#3131496

I found a sample of something I have done. I haven't looked internally at what it's actually doing as I was told to just use it, but it seems to work. It actually won't allow anything other than a number in a textbox.

Textbox control (Note onKeyPress):
<asp:TextBox CssClass="requiredField" ID="YearsBillingTextBox" runat="server" Width="50px" MaxLength="3" 
            onKeyPress="event.returnValue=isNumberKey(event)" />
Javascript function:
//Only allow numeric input
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform