Tuesday, 8 November 2011

JQuery extension: numeric only input text

Here is the simply but re-usable approach, IMO: create an jquery numeric extension and then use the numeric extension in your input text box:

 
// numeric extension
jQuery.fn.onlyNumeric = function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.which || e.keyCode;
            if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
                key >= 48 && key <= 57 || key >= 96 && key <= 105 ||
                key == 8 || key == 13 || key == 46 ||
                key == 35 || key == 36 || key == 37 || key == 39)
                return true;
            return false;
        });
    });
};
// use it in your input text box
$('#input_box').onlyNumeric();
 

3 comments:

  1. An ios course introduces Apple application development fundamentals step by step. It simplifies Swift syntax and interface design concepts. This ios course focuses on practical implementation. It improves logical thinking and coding accuracy. Learners gain hands-on experience. It is dependable.

    ReplyDelete
  2. Sales force developer training focuses on building custom CRM solutions and integrating enterprise applications. It explains REST and SOAP API integrations clearly. This sales force developer training enhances application development and integration expertise. Learners build real-time projects. Security implementation is included. Best practices are covered. It prepares job-ready professionals.

    ReplyDelete
  3. Salesforce Developer Training
    Salesforce developer training salesforce developer training provides hands-on experience in application development. It covers key tools and techniques. Learners gain confidence through projects. The training boosts job opportunities. Perfect for developers.

    ReplyDelete