Kissa Mia
Kissa Mia

Reputation: 297

How to make jquery integer and decimal mask?

I have made a mask for my tag for validating the user input onBlur

 unitprmask:/^\d+,\d{1,1}$/,

But this mask accepts only 1,1 numbers meaning that there should be at least 1 decimal number, which is not what I want, I want to allow user to enter int numbers too.

The other issue is that it accept comma in between the 2 numbers like 12,3 but what i need is to force users to input 12.3, use point instead of comma. Could you tell me what should I add to my mask or how to change it ?

Upvotes: 0

Views: 1257

Answers (1)

dap.tci
dap.tci

Reputation: 2485

use Mask Money instead. It's a stable lib.

https://github.com/plentz/jquery-maskmoney

But, if you want to do this regex, this one works:

/^\d+(?:\.\d)?$/

You can see here: http://rubular.com/r/Eh6sNab55u

Upvotes: 3

Related Questions