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


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

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);

Danasegarane Arunachalam replied to abinav shankar on 01-Feb-12 01:08 AM
Check this one


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