简体   繁体   中英

Regular Expression in Javascript for restricting two numerals

I had to restrict upto two numerals after decimal points, but i have to allow some special characters, how can we do that,

Ex:

123.12%

345463543.12$

The character may be units/metrics it may have special characters as well as alphabets accompanied with that

Here you go:

[0-9]+(\.[0-9][0-9])[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/A-Za-z]?

You can test it here


@evolutionxbox Here's an explanation of each of the parts:

[0-9]+

Checks for at least 1 number

(\.[0-9][0-9]?)

Decimal numbers

[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/A-Za-z]?

Allows for special character and alphabetical characters

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