-3

I am having problems with my inputs having to accept only numbers like integers only and float, the problem is when everytime I input a value like "50.50", only "50.5" will be saved into the database, and when I input 500.50, "500.5" will be saved to the database, and if I input "50.0050" what will be saved to the database is "50.005". how can I make the input fields with this class save "50.50" if I input 50.50 or "50.75" if input 50.75 and so on? and if there is a way that zero "0" and other characters like letters and punctuation marks other than period "." will automatically be removed upon input?

and one more thing, could this be possibly done after the user lost focus from the input field? or after every keypress perhaps?

this is what i have so far:

<script>
$(".digitOnly").each(function() {
var .digitOnly = $.isNumeric($(this).html()) 
$(this).val();
else{
($(this).inputVal = "");
)
});
</script>

to those who have down-rated this post, you should have tried first your suggestion and the one I am trying to achieve as your suggested link still doesn't accept the value like "50.50".

but if you know such a result, I would greatly appreciate it than down-rating my post.

I am pertaining to this post:

How to only accept numbers like integer and float in an input field values using jQuery

this does not accept the input "50.50".

Kiran Joshi
  • 1,758
  • 2
  • 11
  • 34
makLoy
  • 23
  • 5

1 Answers1

0

How any number, other than a string, appear in a database has really nothing to do with JQuery and everything to do with Database Design at the Field level. You need to specify Data Type and number of decimals for storage and display and stuff like that.

If you want to remember how digits are really added you need to add something like a String (varchar, etc), but then you need to have two fields for every one (one with the number and one with the string) or typecast the String version if you plan to use it in any numerical context.

On the loss of focus use:

$(this).blur(...

On after keypress use:

$(this).keyup(...

or

$(this).change(...
Jan Andersen
  • 773
  • 1
  • 6
  • 13