ANJYR
ANJYR

Reputation: 2623

Regex for Currency with specific length in javascript

I'm currently using the following regex expression for currency in my input form fields: my requirement is maximum length of input field is 16 digit and after that decimal (.) then two digit. i try this expression but it not working. something wrong with my expression.

^(\d*\.\d{1,2}|\d+){0,16}$

Valid

 //space- if user leave input box as blank 
0
0.9
9999
9999.0
9999.00
9999999999999999.00

Invalid

0.00.
99999999999999999.00
999......000
AB999
$99.00

Note:-Alphabet and symbol will not allowed (only . will allow)

Upvotes: 0

Views: 133

Answers (1)

anubhava
anubhava

Reputation: 786329

You can use this regex:

^\d{0,16}(?:.\d{1,2})?$

Regex Demo

Upvotes: 1

Related Questions