Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
Hi all,
I need a regular expression to validate decimal value ranges from -12.0 to +12.0
Search gave many regex but nothing worked. Anybody having correct rgex for this please help.
Thanks in advance
Posted 2-Dec-12 23:01pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Doing this kind of validation with a regexp is not the simplest way. Usually, you convert the string to its numerical value and compare to the bounds of the allowed range.
If you really want a regexp, you need to:
- accept the optional sign character, followed by
        - the digit 1 followed by the digit 2 followed by an optional . followed by any number of 0
        - or a single digit or the pair 10 or the pair 11 followed by an optional . followed by any digit(s)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 254
1 Nirav Prabtani 223
2 Sergey Alexandrovich Kryukov 209
3 _Amy 165
4 Richard MacCutchan 135
0 OriginalGriff 7,799
1 Sergey Alexandrovich Kryukov 6,966
2 Maciej Los 3,994
3 Peter Leow 3,708
4 CHill60 2,742

Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100