I want only a floating point value in my text box and any characters and alphabetic letters are filtered out, the closest solution I found is:
jQuery(".sow-items .discovery_repeat input.hours").live("keyup", function(e) { $(this).val($(this).val().replace(/[^\d]/, '')); });
but also filters out the decimal point. how to exclude the decimal character from the specified filter or any new sentences?
Try the following:
jQuery(".sow-items .discovery_repeat input.hours").live("keyup", function(e) { $(this).val($(this).val().replace(/[^\d.]/g, '')); });
/\b[-+]?[0-9]*\.?[0-9]+\b/g or /^[-+]?[0-9]*\.?[0-9]+$/ should do the trick if you don't want to allow numbers like "1.4E-15".
/\b[-+]?[0-9]*\.?[0-9]+\b/g
/^[-+]?[0-9]*\.?[0-9]+$/
http://www.regular-expressions.info/floatingpoint.html contains some suggestions for this unusual case.
jQuery(".sow-items .discovery_repeat input.hours").live("keyup", function(e) { var newVal = $(this).val().replace(/[^\d.]/, '').split("."); if ( newVal.length>2 ) newVal.length = 2; newVal.join("."); $(this).val(newVal); });
@Dave Newton: Only one . ..
.
You need to match either not a digit or not a point, and the point must be escaped
jQuery(".sow-items .discovery_repeat input.hours").live("keyup", function(e) { $(this).val($(this).val().replace(/[^\d]|[^\.]/, '')); });
Source: https://habr.com/ru/post/1488017/More articles:ASP.NET MVC4 Source URL for HTML5 Video - c #How to identify / delete non-UTF-8 characters in R - rHow to install swagger with gae + jersey + maven? - google-app-engineTwo different ways to declare an array - javaEnter to get only two decimal places - javascriptSQL output from ActiveRecord migration without executing it (not rails!) - ruby | fooobar.com$ facebook-> getUser () suddenly stopped working - phpR: Binary matrix for all possible unique results - matrixphp sdk only works on https connections - sslThe dynamic CRM module registration tool returns an unsecured or incorrectly protected error - dynamics-crm-2011All Articles