Regular expression for length limit 10 digit before decimal till 2 decimal place with Number only?












0














i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed

1

1111111111

111

1111111111.22

.2

1.2

1.22

Not allowed

4.

.

-1

abc

Null

Emptystring

""

1.222

-1.22

111111111111

tried but not working



^[0-9]*(.[0-9]{0,2})?$









share|improve this question
























  • How did you devise this regex? Your regex doesn't match the - character for sign.
    – Dai
    Nov 13 at 5:34












  • @CertainPerformance fixed
    – Deepak Jain
    Nov 13 at 5:39










  • Do you want to match 1.2? or 1.22
    – vks
    Nov 13 at 7:05










  • @vks both needed
    – Deepak Jain
    Nov 14 at 6:16






  • 1




    @DeepakJain the answer u accepted accepts . as well.1. as well
    – vks
    Nov 14 at 6:25


















0














i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed

1

1111111111

111

1111111111.22

.2

1.2

1.22

Not allowed

4.

.

-1

abc

Null

Emptystring

""

1.222

-1.22

111111111111

tried but not working



^[0-9]*(.[0-9]{0,2})?$









share|improve this question
























  • How did you devise this regex? Your regex doesn't match the - character for sign.
    – Dai
    Nov 13 at 5:34












  • @CertainPerformance fixed
    – Deepak Jain
    Nov 13 at 5:39










  • Do you want to match 1.2? or 1.22
    – vks
    Nov 13 at 7:05










  • @vks both needed
    – Deepak Jain
    Nov 14 at 6:16






  • 1




    @DeepakJain the answer u accepted accepts . as well.1. as well
    – vks
    Nov 14 at 6:25
















0












0








0







i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed

1

1111111111

111

1111111111.22

.2

1.2

1.22

Not allowed

4.

.

-1

abc

Null

Emptystring

""

1.222

-1.22

111111111111

tried but not working



^[0-9]*(.[0-9]{0,2})?$









share|improve this question















i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed

1

1111111111

111

1111111111.22

.2

1.2

1.22

Not allowed

4.

.

-1

abc

Null

Emptystring

""

1.222

-1.22

111111111111

tried but not working



^[0-9]*(.[0-9]{0,2})?$






javascript regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 7:11

























asked Nov 13 at 5:33









Deepak Jain

2809




2809












  • How did you devise this regex? Your regex doesn't match the - character for sign.
    – Dai
    Nov 13 at 5:34












  • @CertainPerformance fixed
    – Deepak Jain
    Nov 13 at 5:39










  • Do you want to match 1.2? or 1.22
    – vks
    Nov 13 at 7:05










  • @vks both needed
    – Deepak Jain
    Nov 14 at 6:16






  • 1




    @DeepakJain the answer u accepted accepts . as well.1. as well
    – vks
    Nov 14 at 6:25




















  • How did you devise this regex? Your regex doesn't match the - character for sign.
    – Dai
    Nov 13 at 5:34












  • @CertainPerformance fixed
    – Deepak Jain
    Nov 13 at 5:39










  • Do you want to match 1.2? or 1.22
    – vks
    Nov 13 at 7:05










  • @vks both needed
    – Deepak Jain
    Nov 14 at 6:16






  • 1




    @DeepakJain the answer u accepted accepts . as well.1. as well
    – vks
    Nov 14 at 6:25


















How did you devise this regex? Your regex doesn't match the - character for sign.
– Dai
Nov 13 at 5:34






How did you devise this regex? Your regex doesn't match the - character for sign.
– Dai
Nov 13 at 5:34














@CertainPerformance fixed
– Deepak Jain
Nov 13 at 5:39




@CertainPerformance fixed
– Deepak Jain
Nov 13 at 5:39












Do you want to match 1.2? or 1.22
– vks
Nov 13 at 7:05




Do you want to match 1.2? or 1.22
– vks
Nov 13 at 7:05












@vks both needed
– Deepak Jain
Nov 14 at 6:16




@vks both needed
– Deepak Jain
Nov 14 at 6:16




1




1




@DeepakJain the answer u accepted accepts . as well.1. as well
– vks
Nov 14 at 6:25






@DeepakJain the answer u accepted accepts . as well.1. as well
– vks
Nov 14 at 6:25














2 Answers
2






active

oldest

votes


















2














You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [0-9] simplifies to d.



In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}:



^(?!$)d{0,10}(?:.d{1,2})?$


https://regex101.com/r/Ah8dNu/5






share|improve this answer























  • 11111111111 (11 digit are invalid) not working (only 10 digit allowed)
    – Deepak Jain
    Nov 13 at 5:42










  • 10 digit before Decimal
    – Deepak Jain
    Nov 13 at 5:44










  • This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
    – vks
    Nov 13 at 7:50










  • @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
    – CertainPerformance
    Nov 13 at 8:20






  • 1




    @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
    – vks
    Nov 14 at 6:28



















0














I have also prepared below RegEx.



Seems this will also work.



^[0-9]{1,10}((.)[0-9]{0,2}){0,1}$






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%2f53274438%2fregular-expression-for-length-limit-10-digit-before-decimal-till-2-decimal-place%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [0-9] simplifies to d.



    In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}:



    ^(?!$)d{0,10}(?:.d{1,2})?$


    https://regex101.com/r/Ah8dNu/5






    share|improve this answer























    • 11111111111 (11 digit are invalid) not working (only 10 digit allowed)
      – Deepak Jain
      Nov 13 at 5:42










    • 10 digit before Decimal
      – Deepak Jain
      Nov 13 at 5:44










    • This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
      – vks
      Nov 13 at 7:50










    • @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
      – CertainPerformance
      Nov 13 at 8:20






    • 1




      @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
      – vks
      Nov 14 at 6:28
















    2














    You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [0-9] simplifies to d.



    In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}:



    ^(?!$)d{0,10}(?:.d{1,2})?$


    https://regex101.com/r/Ah8dNu/5






    share|improve this answer























    • 11111111111 (11 digit are invalid) not working (only 10 digit allowed)
      – Deepak Jain
      Nov 13 at 5:42










    • 10 digit before Decimal
      – Deepak Jain
      Nov 13 at 5:44










    • This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
      – vks
      Nov 13 at 7:50










    • @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
      – CertainPerformance
      Nov 13 at 8:20






    • 1




      @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
      – vks
      Nov 14 at 6:28














    2












    2








    2






    You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [0-9] simplifies to d.



    In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}:



    ^(?!$)d{0,10}(?:.d{1,2})?$


    https://regex101.com/r/Ah8dNu/5






    share|improve this answer














    You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [0-9] simplifies to d.



    In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}:



    ^(?!$)d{0,10}(?:.d{1,2})?$


    https://regex101.com/r/Ah8dNu/5







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 14 at 7:07

























    answered Nov 13 at 5:40









    CertainPerformance

    74.1k143558




    74.1k143558












    • 11111111111 (11 digit are invalid) not working (only 10 digit allowed)
      – Deepak Jain
      Nov 13 at 5:42










    • 10 digit before Decimal
      – Deepak Jain
      Nov 13 at 5:44










    • This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
      – vks
      Nov 13 at 7:50










    • @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
      – CertainPerformance
      Nov 13 at 8:20






    • 1




      @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
      – vks
      Nov 14 at 6:28


















    • 11111111111 (11 digit are invalid) not working (only 10 digit allowed)
      – Deepak Jain
      Nov 13 at 5:42










    • 10 digit before Decimal
      – Deepak Jain
      Nov 13 at 5:44










    • This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
      – vks
      Nov 13 at 7:50










    • @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
      – CertainPerformance
      Nov 13 at 8:20






    • 1




      @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
      – vks
      Nov 14 at 6:28
















    11111111111 (11 digit are invalid) not working (only 10 digit allowed)
    – Deepak Jain
    Nov 13 at 5:42




    11111111111 (11 digit are invalid) not working (only 10 digit allowed)
    – Deepak Jain
    Nov 13 at 5:42












    10 digit before Decimal
    – Deepak Jain
    Nov 13 at 5:44




    10 digit before Decimal
    – Deepak Jain
    Nov 13 at 5:44












    This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
    – vks
    Nov 13 at 7:50




    This matches . which should not be valid value.regex101.com/r/Ah8dNu/3
    – vks
    Nov 13 at 7:50












    @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
    – CertainPerformance
    Nov 13 at 8:20




    @vks I did notice that, OP had {0,2} in his original code rather than {1, 2}, seemed strange but I thought it was intentional
    – CertainPerformance
    Nov 13 at 8:20




    1




    1




    @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
    – vks
    Nov 14 at 6:28




    @DeepakJain use ^(?!$)d{0,10}(?:.d{1,2})?$ . See demo. regex101.com/r/Ah8dNu/4
    – vks
    Nov 14 at 6:28













    0














    I have also prepared below RegEx.



    Seems this will also work.



    ^[0-9]{1,10}((.)[0-9]{0,2}){0,1}$






    share|improve this answer


























      0














      I have also prepared below RegEx.



      Seems this will also work.



      ^[0-9]{1,10}((.)[0-9]{0,2}){0,1}$






      share|improve this answer
























        0












        0








        0






        I have also prepared below RegEx.



        Seems this will also work.



        ^[0-9]{1,10}((.)[0-9]{0,2}){0,1}$






        share|improve this answer












        I have also prepared below RegEx.



        Seems this will also work.



        ^[0-9]{1,10}((.)[0-9]{0,2}){0,1}$







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 7:01









        Ashish Sapkale

        455212




        455212






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53274438%2fregular-expression-for-length-limit-10-digit-before-decimal-till-2-decimal-place%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

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word