Click here to Skip to main content
12,822,050 members (46,281 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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 3-Dec-12 0:01am

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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2017
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