C#: Min to max number of digits after a decimalHow to validate decimal number input to restrict them to only two decimal places?Validate decimal numbers in JavaScript - IsNumeric()What are the correct version numbers for C#?How do I generate a random int number?Regex to validate a number with only one digit following a decimalhow to limit only two digits after decimal point using Regex ValidatorRegular expression for a decimal with a max of 2 digits before decimal pointRegex on JavaScript to accept only numbers with 2 decimalsregex for decimal value restrict 16 digitHow to limit total number of digits in a decimal numberregular expression for number and decimal points in javascript

Temporarily disable WLAN internet access for children, but allow it for adults

What is Cash Advance APR?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Calculating total slots

Why would a new[] expression ever invoke a destructor?

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

Open a doc from terminal, but not by its name

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

Unexpected behavior of the procedure `Area` on the object 'Polygon'

Mimic lecturing on blackboard, facing audience

What is going on with 'gets(stdin)' on the site coderbyte?

What if a revenant (monster) gains fire resistance?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Can a Canadian Travel to the USA twice, less than 180 days each time?

Fear of getting stuck on one programming language / technology that is not used in my country

Creepy dinosaur pc game identification

Strong empirical falsification of quantum mechanics based on vacuum energy density

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

Why Shazam when there is already Superman?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

Biological Blimps: Propulsion

Why should universal income be universal?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Picking the different solutions to the time independent Schrodinger eqaution



C#: Min to max number of digits after a decimal


How to validate decimal number input to restrict them to only two decimal places?Validate decimal numbers in JavaScript - IsNumeric()What are the correct version numbers for C#?How do I generate a random int number?Regex to validate a number with only one digit following a decimalhow to limit only two digits after decimal point using Regex ValidatorRegular expression for a decimal with a max of 2 digits before decimal pointRegex on JavaScript to accept only numbers with 2 decimalsregex for decimal value restrict 16 digitHow to limit total number of digits in a decimal numberregular expression for number and decimal points in javascript













0















I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.



Valid Example:



*1.12
*1.123
*1.1234
*1.12345


Not Valid:



1
1.1
1.123456


etc.



I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:



//Check if the string is a double 
bool IsDouble(string s)

var regex = new Regex(@"^d+.d5?$");
var check = regex.IsMatch(s);
return check;



A little help would be greatly appreciated.










share|improve this question




























    0















    I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.



    Valid Example:



    *1.12
    *1.123
    *1.1234
    *1.12345


    Not Valid:



    1
    1.1
    1.123456


    etc.



    I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:



    //Check if the string is a double 
    bool IsDouble(string s)

    var regex = new Regex(@"^d+.d5?$");
    var check = regex.IsMatch(s);
    return check;



    A little help would be greatly appreciated.










    share|improve this question


























      0












      0








      0








      I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.



      Valid Example:



      *1.12
      *1.123
      *1.1234
      *1.12345


      Not Valid:



      1
      1.1
      1.123456


      etc.



      I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:



      //Check if the string is a double 
      bool IsDouble(string s)

      var regex = new Regex(@"^d+.d5?$");
      var check = regex.IsMatch(s);
      return check;



      A little help would be greatly appreciated.










      share|improve this question
















      I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.



      Valid Example:



      *1.12
      *1.123
      *1.1234
      *1.12345


      Not Valid:



      1
      1.1
      1.123456


      etc.



      I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:



      //Check if the string is a double 
      bool IsDouble(string s)

      var regex = new Regex(@"^d+.d5?$");
      var check = regex.IsMatch(s);
      return check;



      A little help would be greatly appreciated.







      c# regex validation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 30 '14 at 14:54









      crush

      12.6k74590




      12.6k74590










      asked Jan 30 '14 at 14:25









      kknaguibkknaguib

      4061927




      4061927






















          4 Answers
          4






          active

          oldest

          votes


















          2














          This should do it:



          ^d+.d2,5$





          share|improve this answer























          • Great thanks man!

            – kknaguib
            Jan 30 '14 at 14:32


















          1














          Use the pattern



          "^d+.d2,5?$"


          to match between 2 and 5 characters






          share|improve this answer























          • Thanks! Works like a charm

            – kknaguib
            Jan 30 '14 at 14:36


















          0














          Try this Regex



          you can specify your own range here d2,5



          ^s*-?[1-9]d*(.d2,5)?s*$


          (Or)



          ^(d1,5|d0,5.d2,5)$


          REGEX DEMO






          share|improve this answer























          • This will accept integers that are not allowed.

            – Toto
            Jan 30 '14 at 14:41


















          0














          A non-regex solution

          It also returns the decimal



          public int? DecimalAfter (string strDec, out decimal? decNull)

          int? decAfter = null;
          strDec = strDec.Trim();
          decimal dec;
          if (decimal.TryParse(strDec, out dec))

          decNull = dec;
          int decPos = strDec.IndexOf('.');
          if (decPos == -1)

          decAfter = 0;

          else

          decAfter = strDec.Length - decPos - 1;


          else decNull = null;

          return decAfter;






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21459104%2fc-min-to-max-number-of-digits-after-a-decimal%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            This should do it:



            ^d+.d2,5$





            share|improve this answer























            • Great thanks man!

              – kknaguib
              Jan 30 '14 at 14:32















            2














            This should do it:



            ^d+.d2,5$





            share|improve this answer























            • Great thanks man!

              – kknaguib
              Jan 30 '14 at 14:32













            2












            2








            2







            This should do it:



            ^d+.d2,5$





            share|improve this answer













            This should do it:



            ^d+.d2,5$






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 30 '14 at 14:29









            Patrick QuirkPatrick Quirk

            18k14373




            18k14373












            • Great thanks man!

              – kknaguib
              Jan 30 '14 at 14:32

















            • Great thanks man!

              – kknaguib
              Jan 30 '14 at 14:32
















            Great thanks man!

            – kknaguib
            Jan 30 '14 at 14:32





            Great thanks man!

            – kknaguib
            Jan 30 '14 at 14:32













            1














            Use the pattern



            "^d+.d2,5?$"


            to match between 2 and 5 characters






            share|improve this answer























            • Thanks! Works like a charm

              – kknaguib
              Jan 30 '14 at 14:36















            1














            Use the pattern



            "^d+.d2,5?$"


            to match between 2 and 5 characters






            share|improve this answer























            • Thanks! Works like a charm

              – kknaguib
              Jan 30 '14 at 14:36













            1












            1








            1







            Use the pattern



            "^d+.d2,5?$"


            to match between 2 and 5 characters






            share|improve this answer













            Use the pattern



            "^d+.d2,5?$"


            to match between 2 and 5 characters







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 30 '14 at 14:29









            D StanleyD Stanley

            124k9116180




            124k9116180












            • Thanks! Works like a charm

              – kknaguib
              Jan 30 '14 at 14:36

















            • Thanks! Works like a charm

              – kknaguib
              Jan 30 '14 at 14:36
















            Thanks! Works like a charm

            – kknaguib
            Jan 30 '14 at 14:36





            Thanks! Works like a charm

            – kknaguib
            Jan 30 '14 at 14:36











            0














            Try this Regex



            you can specify your own range here d2,5



            ^s*-?[1-9]d*(.d2,5)?s*$


            (Or)



            ^(d1,5|d0,5.d2,5)$


            REGEX DEMO






            share|improve this answer























            • This will accept integers that are not allowed.

              – Toto
              Jan 30 '14 at 14:41















            0














            Try this Regex



            you can specify your own range here d2,5



            ^s*-?[1-9]d*(.d2,5)?s*$


            (Or)



            ^(d1,5|d0,5.d2,5)$


            REGEX DEMO






            share|improve this answer























            • This will accept integers that are not allowed.

              – Toto
              Jan 30 '14 at 14:41













            0












            0








            0







            Try this Regex



            you can specify your own range here d2,5



            ^s*-?[1-9]d*(.d2,5)?s*$


            (Or)



            ^(d1,5|d0,5.d2,5)$


            REGEX DEMO






            share|improve this answer













            Try this Regex



            you can specify your own range here d2,5



            ^s*-?[1-9]d*(.d2,5)?s*$


            (Or)



            ^(d1,5|d0,5.d2,5)$


            REGEX DEMO







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 30 '14 at 14:31









            Vignesh Kumar AVignesh Kumar A

            18.7k104187




            18.7k104187












            • This will accept integers that are not allowed.

              – Toto
              Jan 30 '14 at 14:41

















            • This will accept integers that are not allowed.

              – Toto
              Jan 30 '14 at 14:41
















            This will accept integers that are not allowed.

            – Toto
            Jan 30 '14 at 14:41





            This will accept integers that are not allowed.

            – Toto
            Jan 30 '14 at 14:41











            0














            A non-regex solution

            It also returns the decimal



            public int? DecimalAfter (string strDec, out decimal? decNull)

            int? decAfter = null;
            strDec = strDec.Trim();
            decimal dec;
            if (decimal.TryParse(strDec, out dec))

            decNull = dec;
            int decPos = strDec.IndexOf('.');
            if (decPos == -1)

            decAfter = 0;

            else

            decAfter = strDec.Length - decPos - 1;


            else decNull = null;

            return decAfter;






            share|improve this answer



























              0














              A non-regex solution

              It also returns the decimal



              public int? DecimalAfter (string strDec, out decimal? decNull)

              int? decAfter = null;
              strDec = strDec.Trim();
              decimal dec;
              if (decimal.TryParse(strDec, out dec))

              decNull = dec;
              int decPos = strDec.IndexOf('.');
              if (decPos == -1)

              decAfter = 0;

              else

              decAfter = strDec.Length - decPos - 1;


              else decNull = null;

              return decAfter;






              share|improve this answer

























                0












                0








                0







                A non-regex solution

                It also returns the decimal



                public int? DecimalAfter (string strDec, out decimal? decNull)

                int? decAfter = null;
                strDec = strDec.Trim();
                decimal dec;
                if (decimal.TryParse(strDec, out dec))

                decNull = dec;
                int decPos = strDec.IndexOf('.');
                if (decPos == -1)

                decAfter = 0;

                else

                decAfter = strDec.Length - decPos - 1;


                else decNull = null;

                return decAfter;






                share|improve this answer













                A non-regex solution

                It also returns the decimal



                public int? DecimalAfter (string strDec, out decimal? decNull)

                int? decAfter = null;
                strDec = strDec.Trim();
                decimal dec;
                if (decimal.TryParse(strDec, out dec))

                decNull = dec;
                int decPos = strDec.IndexOf('.');
                if (decPos == -1)

                decAfter = 0;

                else

                decAfter = strDec.Length - decPos - 1;


                else decNull = null;

                return decAfter;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 30 '14 at 14:59









                paparazzopaparazzo

                37.7k1775140




                37.7k1775140



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21459104%2fc-min-to-max-number-of-digits-after-a-decimal%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript