C# .NET - Regular exp for text box to contain whole number and decimal number

Asked By abinav shankar on 01-Feb-12 01:00 AM

Hi

I need a regular field expression which should allow only whole number and decimal number example I can allow the user to enter values like 5,0.5 and not 0.25 or 0.75
how to do it

smr replied to abinav shankar on 01-Feb-12 01:06 AM
hi

refer this

function test1(str) {
          return /^ *[0-9]+ *$/.test(str);
        }
        function test2(str) {
          return /^\d+$/.test(str);
        }
        function test3(str) {
          return /^\d{3,5}$/.test(str);
        }


follow
http://stackoverflow.com/questions/308122/simple-regular-expression-for-a-decimal-with-a-precision-of-2
http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3&AspxAutoDetectCookieSupport=1
Danasegarane Arunachalam replied to abinav shankar on 01-Feb-12 01:08 AM
Check this one

(100|[1-9]\d?(?:\.\d+)?)

Essentially the second part is:
[1-9] - a character between 1 and 9
\d? - optionally followed by another digit
(?: - start a non-capturing group
\.\d+ - a decimal point followed by one or more digits
) ?- close the non-capturing group and make matching its contents optional