I want my textbox to have only floating point value, and filter out any symbols and alphabetical letters, the nearest solution i found is:
jQuery(".sow-items .discovery_repeat input.hours").live("keyup", function(e) {
$(this).val($(this).val().replace(/[^\d]/, ''));
});
but it also filters out decimal point. how to exclude decimal from the above filter or any new suggestions?
Try this:
/\b[-+]?[0-9]*\.?[0-9]+\b/g
or/^[-+]?[0-9]*\.?[0-9]+$/
should do the trick, unless you want to allow numbers like "1.4E-15" in there.http://www.regular-expressions.info/floatingpoint.html has some suggestions for that unusual case.
You need to match either non digit or non dot and the dot needs to be escaped
@Dave Newton: Only one
.
..