jquery - Allow Decimal value in number -
i have form filed in amount has enter. amount separated commas , decimal not allowed. want allow decimal in amount. in advance...
here code :
(function($, undefined) { "use strict"; $(function() { var $form = $( ".number" ); var $input = $form.find( ".no" ); $input.on( "keyup", function( event ) { var selection = window.getselection().tostring(); if ( selection !== '' ) { return; } if ( $.inarray( event.keycode, [38,40,37,39] ) !== -1 ) { return; } var $this = $( ); var input = $this.val(); var input = input.replace(/[\d\s\._\-]+/g, ""); input = input ? parseint( input, 10 ) : 0; $this.val( function() { return ( input === 0 ) ? "" : input.tolocalestring( "en-us" ); }); }); }); })(jquery);
$(function() { var $form = $( ".number" ); var $input = $form.find( ".no" ); $input.on( "keyup", function( event ) { var selection = window.getselection().tostring(); if ( selection !== '' ) { return; } if ( $.inarray( event.keycode, [38,40,37,39] ) !== -1 ) { return; } var $this = $( ); var input = $this.val(); input = input ? parsefloat( input) : 0; $this.val( function() { return ( input === 0 ) ? "" : input.tolocalestring( "en-us" ); } ); } ); }); })(jquery);
Comments
Post a Comment