Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:23:32+00:00 2026-06-06T16:23:32+00:00

I use the following function for decimal validation it was work fine in IE

  • 0

I use the following function for decimal validation it was work fine in IE and Chrome.But not working in Fire Fox.If I run this code in fire fox i Cant enter any character.How to solve this?

   $('.decimalValidate').live('keypress', function (event) {
       var decimalval= $(this).val();
       if ((event.which > 47 && event.which < 58)) {
           return true;
       }
       if ((event.which == 8 || event.which == 46) && decimalval.indexOf('.') == -1)  {
           return true;
       }
       return false;                          
   });

this condition is not working in FF

if ((event.which == 8 || event.which == 46) && decimalval.indexOf('.') == -1)  {
    return true;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:23:36+00:00Added an answer on June 6, 2026 at 4:23 pm

    You can try this .on() delegate event handler with jQuery 1.7.x, because live() is deprecated.

    Syntax of .on() for delegate event is:

    $(container).on(eventNaem, target, eventHandler)
    

    Here, container points to any Static-element that don’t appears to DOM dynamically.

    $(document).on('keypress', '.decimalValidate', function(event) {
    
         // var decimalid = $(this).attr("id"); // I think you don't need this
    
        var decimalval = $(this).val(); // or this.value
    
        if ((event.which > 47 && event.which < 58)) {
            return true;
        }
        if ((event.which == 8 || event.which == 46) && decimalval.indexOf('.') == -1) {
            return true;
        }
        return false;
    });
    

    According to comment

    • backspace is not working

    You are handling with backspace and delete with following condition:

    (event.which == 8 || event.which == 46) && decimalval.indexOf('.') == -1
    

    which set validation like that:

    if you text box contains no . and backspace or delete key pressed the execute code within that condition block.

    Above condition will fails when you text box contains . and you pressed backspace or delete key and condition block will not execute any return statement.


    How to enable backspace when value contains . (dot)

    Change the condition like:

    just remove && decimalval.indexOf('.') >= -1 from the condition

    (event.which == 8 || event.which == 46) 
    

    AIM: yes my aim is not enter more than one dot in the input ( by @user )

    Full code

    $('.decimalValidate').on('keyup', function(e) {
        var decimalval = $(this).val();
    
        var decimalvalidate = ApplyDecimalFilter(decimalval, e);
        if (decimalvalidate == false) return false;
    });
    
    
    
    function ApplyDecimalFilter(id, event) {
        try {
            return NewDecimalFilter(id, event);
        } catch (e) {
            alert(e.message);
        }
    }
    
    function NewDecimalFilter(o, event) {
        if (o.match(/\./g) && o.match(/\./g).length > 1) {
            $(event.target).val(o.replace(/\.$/, ''))
            return false;
        }
        if ((event.which > 47 && event.which < 58) || event.which == 8 || event.which == 46) {
            return true;
        }
        return false;
    }
    

    Working sample

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the following jquery statements but i get error in this function onGetDataSuccess(result)
how to use following function public IList<T> GetAll(Expression<Func<T, bool>> whereCondition) { return this.ObjectSet.Where(whereCondition).ToList<T>(); }
For instance I have the following value: 0.000018 This is 6 decimal places, but
I use the following function to show controls on my form: class procedure TFormMain.FadeControls(ctrl:Array
I use the following function to rename thumbnails. For example, if I upload a
We use the following function to auto detect if we are on a machine
i have to use the following function, to change the input's type <input class=input
I use the following javascript function, function get_check_value(formId,checkboxId,TxtboxId) { alert(formId); var c_value = ;
I would like to know if I can use the following JQuery function on
I use the following the jquery statements to call my php controller function, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.