How do I force certain input fields in my form to accept only positive values with up to two decimal points?

I am using jquery calx to create a form that works out several company expenses for an ecommerce site.
In some of the fields - all those with class checkNegative (or marked with #A2#, #A18#, #A19#, #A20#, #A28# - I would like to force users to insert only positive values with up to two decimal places.

How do I do it?

I have tried using this function but it sort of does not work.
$(".checkNegative").bind("change paste input", function(){
	$(this).val( Math.abs($(this).val()) );

Open in new window

With this code I cannot enter any negative values because as soon as I try it gives me NaN error (whereas I would like like to remove the "-" sign when typed). However I am unable to add any numbers that are not whole (like with decimal places)

Please help

thanks in advance

I am attaching the code for testing.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Here you go:,output

$(".checkNegative").on("input", function(e){
	var t = isNaN(Number( ? 0 :;

Open in new window

badwolfffAuthor Commented:

it doesn't work right. When I try to add a normal positive number like 11.55 it forces me to take it as 1155.
I need to be able to put in

11.5 (this already becomes 11.50)

if instead I were to put in

-11 > becomes > 11
-11.55 > becomes > 11.55
-11.5 > becomes > 11.50

there is another problem with your function. If you try to add any values to A18 - A20, I get strange numbers automatically in A28 (while it should not change at all)

I think we need a Regex here but I don't know how to write it.

badwolfffAuthor Commented:
I managed it myself

thanks anyways

$("#valoredonazione").bind("change paste input", function () {
    if ($(this).val() < 0) {
        window.console && console.log('condition met');
        $(this).val(function (index, value) {
            return value.replace('-', '');

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

RobOwner (Aidellio)Commented:
Cool. Glad you got your answer :)
Michel PlungjanIT ExpertCommented:
Or just

$("#valoredonazione").on("change paste input", function () {
   var val = $(this).val();
    if (parseFloat(val) < 0) {
        window.console && console.log('condition met');
        $(this).val(val.replace('-', ''));

Open in new window

badwolfffAuthor Commented:
I solved it myself
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.