John
John

Reputation: 6622

Validate decimals on quarter values

I have a decimal field which should allow only quarter values: 1.0, 1.25, 1.5, 1.75, but not values like 1.33 or 1.78. How can I validate this?

Upvotes: 0

Views: 236

Answers (2)

Santhosh
Santhosh

Reputation: 29174

Another solution

(num % 0.25).zero?

Upvotes: 2

Debadatt
Debadatt

Reputation: 6015

To match such number use regex pattern

(?!0\d)\d+(?:[.](?:25|5|75|0)0*)?(?!\d)

Hope this regex could help

Upvotes: 2

Related Questions