简体   繁体   中英

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)

You can use this regex:

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

Regex Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM