Results 1 to 2 of 2

Thread: javascript function

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    41

    Unhappy javascript function

    hi ,

    i am in a fix . i have a text box that by id company name. when the user enters numbers how do i restrict him from entering numbers. can anyone tell me how to do this using javascript.


    thanks,
    abhiram.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: javascript function

    Have just found this on the net (won't take the credit for this code as it's from www.webreference.com):

    Code:
    function numeralsOnly(evt) {
        evt = (evt) ? evt : event;
        var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
            ((evt.which) ? evt.which : 0));
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            alert("Enter numerals only in this field.");
            return false;
        }
        return true;
    }
    The field's event handler would be configured like the following:

    Code:
    onkeypress="return numeralsOnly(event)"

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width