• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2038
  • Last Modified:

Need Regular Expression to validate for 2 decimal places

Would like the regular expression to force a user to supply a decimal with 2 decimal places. Example : 12.56
0
jazzcatone
Asked:
jazzcatone
  • 3
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
Think like this:

^[0-9]+\.[0-9]{2}$
0
 
jazzcatoneAuthor Commented:
Looks like this worked. Thanks .
0
 
Kevin CrossChief Technology OfficerCommented:
Glad. Figured as this should be consistent across most environments, but tested in Java.

+Must begin with number.
+Must have . in it.
+Must end with exactly two digits.
0
 
Kevin CrossChief Technology OfficerCommented:
If you want to allow .25 the same as 0.25, then you can change to this:

^[0-9]*\.[0-9]{2}$

Not sure if this works in all environments, but it should but you also have the \d representing numeric values.

^\d*\.\d{2}$

Hope all that helps.
0
 
binoboseCommented:
i need to validate a number like 1.20
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now