Reputation: 99
I have used the below regex but it accept all values after decimal point. I want only whole numbers ( eg: 12) and half decimal point (eg 12.5)
Regex regex = new Regex("[^0-9.]+"); I want the below behavior.
For example
Upvotes: 0
Views: 605
Reputation: 520978
Try using this pattern:
\d+(?:\.5)?
This would match whole numbers, as well as numbers which half just a decimal component of 0.5
. If you also want to allow for 0.0
decimal endings, then use:
\d+(?:\.[05])?
For your actual code, you may use:
Regex regex = new Regex("@\d+(?:\.5)?");
Upvotes: 1