I have one one web page which one one textbox for receiving the dollar value. My requirement is the user should insert the digit following by a $ sysmbol. And the second requirement is the user has the permission to insert only like this $123.45. Before the decimal point it should not exceed three digits and after the decimal point it should not exceed two digits. Please help me by providing the appropriate regular expression for validating this value.. thanks in advance.
Try:
\$\d{1,3}(\.\d{1,2})?
\\$ = a dollar, escaped as it is a special character
\\d = a digit; {1,3} = between 1 and 3 repetitions
()? = an optional group:
\\. = a dot (escaped) \\d{1,2} = one or two digits
To play regular expressions (and test them) you can use Expresso or a similar tool.
\$\d{1,3}\.\d{1,2}
or
\$\d{1,3}\.\d{2}
if you want to force the last decimal to have 2 digits
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.