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;
}
You can try this
.on()delegate event handler with jQuery 1.7.x, becauselive()is deprecated.Syntax of
.on()for delegate event is:Here,
containerpoints to anyStatic-elementthat don’t appears to DOM dynamically.According to comment
backspaceis not workingYou are handling with
backspaceanddeletewith following condition:which set validation like that:
if you text box contains no
.andbackspaceordeletekey pressed the execute code within that condition block.Above condition will fails when you text box contains
.and you pressedbackspaceordeletekey and condition block will not execute anyreturnstatement.How to enable
backspacewhen value contains.(dot)Change the condition like:
just remove
&& decimalval.indexOf('.') >= -1from the conditionAIM: yes my aim is not enter more than one dot in the input ( by @user )
Full code
Working sample