Regular Expression to Validate if it is not a Decimal or Integer NumberHow to validate an email address in JavaScript?A comprehensive regex for phone number validationWhat is the best regular expression to check if a string is a valid URL?Is there a regular expression to detect a valid regular expression?How to validate an email address using a regular expression?What are the correct version numbers for C#?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular Expressions: Is there an AND operator?How do you use a variable in a regular expression?

the meaning of 'carry' in a novel

Simple function that simulates survey results based on sample size and probability

Is the Starlink array really visible from Earth?

What are the real benefits of using Salesforce DX?

Crossing US border with music files I'm legally allowed to possess

how to grep in the output of ls -a

I unknowingly submitted plagarised work

Writing with dry erase marker on Shabbos, is it permitted?

Is CD audio quality good enough?

Were pens caps holes designed to prevent death by suffocation if swallowed?

Flying domestically in the US, is my State Issued ID all I need to get past security?

Is there an efficient way to replace text matching the entire content of one file with the entire content of another file?

Why are C64 games inconsistent with which joystick port they use?

What does the view outside my ship traveling at light speed look like?

Are these reasonable traits for someone with autism?

A steel cutting sword?

Have 1.5% of all nuclear reactors ever built melted down?

Why do they consider the Ori false gods?

Why does Mjolnir fall down in Age of Ultron but not in Endgame?

I think I may have violated academic integrity last year - what should I do?

How should I introduce map drawing to my players?

How to respond to an upset student?

At what point in European history could a government build a printing press given a basic description?

Count Even Digits In Number



Regular Expression to Validate if it is not a Decimal or Integer Number


How to validate an email address in JavaScript?A comprehensive regex for phone number validationWhat is the best regular expression to check if a string is a valid URL?Is there a regular expression to detect a valid regular expression?How to validate an email address using a regular expression?What are the correct version numbers for C#?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular Expressions: Is there an AND operator?How do you use a variable in a regular expression?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box



Examples



  1. 1.. - Catch // consecutive Repeating dots

  2. ABC - Catch // All Alphabets

  3. 1.1.1- Catch // dots repeating in a number

  4. !,@,#- Catch // All Special Characters

My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.



void T1_HTextChanged(object sender, EventArgs e) 
[.]2"))


MessageBox.Show("Please enter only numbers.");
T1_H.Text="";











share|improve this question
























  • you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.

    – Vinícius Gabriel
    Mar 24 at 6:07











  • P.S.: You can negate the regex to check if the input is not a number... obviously

    – Vinícius Gabriel
    Mar 24 at 6:09











  • Try this regex: ^[0-9]+([.][0-9]1,2)?$. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.

    – Rahul Sharma
    Mar 24 at 6:12







  • 4





    int.TryParse and decimal.TryParse are better options than regex.

    – Chetan Ranpariya
    Mar 24 at 6:14












  • Also you can use NumericUpDown instead of TextBox.

    – Alexander Petrov
    Mar 24 at 9:33

















0















I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box



Examples



  1. 1.. - Catch // consecutive Repeating dots

  2. ABC - Catch // All Alphabets

  3. 1.1.1- Catch // dots repeating in a number

  4. !,@,#- Catch // All Special Characters

My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.



void T1_HTextChanged(object sender, EventArgs e) 
[.]2"))


MessageBox.Show("Please enter only numbers.");
T1_H.Text="";











share|improve this question
























  • you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.

    – Vinícius Gabriel
    Mar 24 at 6:07











  • P.S.: You can negate the regex to check if the input is not a number... obviously

    – Vinícius Gabriel
    Mar 24 at 6:09











  • Try this regex: ^[0-9]+([.][0-9]1,2)?$. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.

    – Rahul Sharma
    Mar 24 at 6:12







  • 4





    int.TryParse and decimal.TryParse are better options than regex.

    – Chetan Ranpariya
    Mar 24 at 6:14












  • Also you can use NumericUpDown instead of TextBox.

    – Alexander Petrov
    Mar 24 at 9:33













0












0








0








I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box



Examples



  1. 1.. - Catch // consecutive Repeating dots

  2. ABC - Catch // All Alphabets

  3. 1.1.1- Catch // dots repeating in a number

  4. !,@,#- Catch // All Special Characters

My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.



void T1_HTextChanged(object sender, EventArgs e) 
[.]2"))


MessageBox.Show("Please enter only numbers.");
T1_H.Text="";











share|improve this question
















I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box



Examples



  1. 1.. - Catch // consecutive Repeating dots

  2. ABC - Catch // All Alphabets

  3. 1.1.1- Catch // dots repeating in a number

  4. !,@,#- Catch // All Special Characters

My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.



void T1_HTextChanged(object sender, EventArgs e) 
[.]2"))


MessageBox.Show("Please enter only numbers.");
T1_H.Text="";








c# regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 8:48









James Z

11.2k72037




11.2k72037










asked Mar 24 at 5:59









Srinath SriSrinath Sri

1




1












  • you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.

    – Vinícius Gabriel
    Mar 24 at 6:07











  • P.S.: You can negate the regex to check if the input is not a number... obviously

    – Vinícius Gabriel
    Mar 24 at 6:09











  • Try this regex: ^[0-9]+([.][0-9]1,2)?$. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.

    – Rahul Sharma
    Mar 24 at 6:12







  • 4





    int.TryParse and decimal.TryParse are better options than regex.

    – Chetan Ranpariya
    Mar 24 at 6:14












  • Also you can use NumericUpDown instead of TextBox.

    – Alexander Petrov
    Mar 24 at 9:33

















  • you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.

    – Vinícius Gabriel
    Mar 24 at 6:07











  • P.S.: You can negate the regex to check if the input is not a number... obviously

    – Vinícius Gabriel
    Mar 24 at 6:09











  • Try this regex: ^[0-9]+([.][0-9]1,2)?$. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.

    – Rahul Sharma
    Mar 24 at 6:12







  • 4





    int.TryParse and decimal.TryParse are better options than regex.

    – Chetan Ranpariya
    Mar 24 at 6:14












  • Also you can use NumericUpDown instead of TextBox.

    – Alexander Petrov
    Mar 24 at 9:33
















you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.

– Vinícius Gabriel
Mar 24 at 6:07





you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.

– Vinícius Gabriel
Mar 24 at 6:07













P.S.: You can negate the regex to check if the input is not a number... obviously

– Vinícius Gabriel
Mar 24 at 6:09





P.S.: You can negate the regex to check if the input is not a number... obviously

– Vinícius Gabriel
Mar 24 at 6:09













Try this regex: ^[0-9]+([.][0-9]1,2)?$. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.

– Rahul Sharma
Mar 24 at 6:12






Try this regex: ^[0-9]+([.][0-9]1,2)?$. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.

– Rahul Sharma
Mar 24 at 6:12





4




4





int.TryParse and decimal.TryParse are better options than regex.

– Chetan Ranpariya
Mar 24 at 6:14






int.TryParse and decimal.TryParse are better options than regex.

– Chetan Ranpariya
Mar 24 at 6:14














Also you can use NumericUpDown instead of TextBox.

– Alexander Petrov
Mar 24 at 9:33





Also you can use NumericUpDown instead of TextBox.

– Alexander Petrov
Mar 24 at 9:33












3 Answers
3






active

oldest

votes


















1














If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$.



You can test it here https://regex101.com/r/UB6eRT/1



If you want to know if it's a valid number you can also try to convert it and check if you get an error.






share|improve this answer
































    1














    Try this regex:



    ^[0-9]+([.][0-9]1,2)?$


    Explanation:



    • ^ asserts position at start of a line

    • Match a single character present in the list below [0-9]+


    • + Quantifier — Matches between one and unlimited times, as many times as possible,
      giving back as needed (greedy)
      0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

    • 1st Capturing Group ([.][0-9]1,2)?


    • ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

    • Match a single character present in the list below [.]
      . matches the character . literally (case sensitive)

    • Match a single character present in the list below [0-9]1,2
      1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy)

    • 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

    • $ asserts position at the end of a line

    Working example: https://regex101.com/r/iRaRPX/1/



    It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.






    share|improve this answer
































      0














      If you want to achieve this with Regular expression, you can use.



      ^(d*.)?d+$


      Demo



      But please be aware that you can use Decimal.TryParse as well. You can read more on Decimal.TryParse here






      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%2f55321134%2fregular-expression-to-validate-if-it-is-not-a-decimal-or-integer-number%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$.



        You can test it here https://regex101.com/r/UB6eRT/1



        If you want to know if it's a valid number you can also try to convert it and check if you get an error.






        share|improve this answer





























          1














          If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$.



          You can test it here https://regex101.com/r/UB6eRT/1



          If you want to know if it's a valid number you can also try to convert it and check if you get an error.






          share|improve this answer



























            1












            1








            1







            If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$.



            You can test it here https://regex101.com/r/UB6eRT/1



            If you want to know if it's a valid number you can also try to convert it and check if you get an error.






            share|improve this answer















            If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$.



            You can test it here https://regex101.com/r/UB6eRT/1



            If you want to know if it's a valid number you can also try to convert it and check if you get an error.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 24 at 6:18

























            answered Mar 24 at 6:12









            François P.François P.

            2,125716




            2,125716























                1














                Try this regex:



                ^[0-9]+([.][0-9]1,2)?$


                Explanation:



                • ^ asserts position at start of a line

                • Match a single character present in the list below [0-9]+


                • + Quantifier — Matches between one and unlimited times, as many times as possible,
                  giving back as needed (greedy)
                  0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                • 1st Capturing Group ([.][0-9]1,2)?


                • ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

                • Match a single character present in the list below [.]
                  . matches the character . literally (case sensitive)

                • Match a single character present in the list below [0-9]1,2
                  1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy)

                • 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                • $ asserts position at the end of a line

                Working example: https://regex101.com/r/iRaRPX/1/



                It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.






                share|improve this answer





























                  1














                  Try this regex:



                  ^[0-9]+([.][0-9]1,2)?$


                  Explanation:



                  • ^ asserts position at start of a line

                  • Match a single character present in the list below [0-9]+


                  • + Quantifier — Matches between one and unlimited times, as many times as possible,
                    giving back as needed (greedy)
                    0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                  • 1st Capturing Group ([.][0-9]1,2)?


                  • ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

                  • Match a single character present in the list below [.]
                    . matches the character . literally (case sensitive)

                  • Match a single character present in the list below [0-9]1,2
                    1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy)

                  • 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                  • $ asserts position at the end of a line

                  Working example: https://regex101.com/r/iRaRPX/1/



                  It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.






                  share|improve this answer



























                    1












                    1








                    1







                    Try this regex:



                    ^[0-9]+([.][0-9]1,2)?$


                    Explanation:



                    • ^ asserts position at start of a line

                    • Match a single character present in the list below [0-9]+


                    • + Quantifier — Matches between one and unlimited times, as many times as possible,
                      giving back as needed (greedy)
                      0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                    • 1st Capturing Group ([.][0-9]1,2)?


                    • ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

                    • Match a single character present in the list below [.]
                      . matches the character . literally (case sensitive)

                    • Match a single character present in the list below [0-9]1,2
                      1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy)

                    • 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                    • $ asserts position at the end of a line

                    Working example: https://regex101.com/r/iRaRPX/1/



                    It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.






                    share|improve this answer















                    Try this regex:



                    ^[0-9]+([.][0-9]1,2)?$


                    Explanation:



                    • ^ asserts position at start of a line

                    • Match a single character present in the list below [0-9]+


                    • + Quantifier — Matches between one and unlimited times, as many times as possible,
                      giving back as needed (greedy)
                      0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                    • 1st Capturing Group ([.][0-9]1,2)?


                    • ? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

                    • Match a single character present in the list below [.]
                      . matches the character . literally (case sensitive)

                    • Match a single character present in the list below [0-9]1,2
                      1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy)

                    • 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

                    • $ asserts position at the end of a line

                    Working example: https://regex101.com/r/iRaRPX/1/



                    It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 24 at 6:57

























                    answered Mar 24 at 6:18









                    Rahul SharmaRahul Sharma

                    8301617




                    8301617





















                        0














                        If you want to achieve this with Regular expression, you can use.



                        ^(d*.)?d+$


                        Demo



                        But please be aware that you can use Decimal.TryParse as well. You can read more on Decimal.TryParse here






                        share|improve this answer



























                          0














                          If you want to achieve this with Regular expression, you can use.



                          ^(d*.)?d+$


                          Demo



                          But please be aware that you can use Decimal.TryParse as well. You can read more on Decimal.TryParse here






                          share|improve this answer

























                            0












                            0








                            0







                            If you want to achieve this with Regular expression, you can use.



                            ^(d*.)?d+$


                            Demo



                            But please be aware that you can use Decimal.TryParse as well. You can read more on Decimal.TryParse here






                            share|improve this answer













                            If you want to achieve this with Regular expression, you can use.



                            ^(d*.)?d+$


                            Demo



                            But please be aware that you can use Decimal.TryParse as well. You can read more on Decimal.TryParse here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 24 at 7:34









                            Anu ViswanAnu Viswan

                            6,2272526




                            6,2272526



























                                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%2f55321134%2fregular-expression-to-validate-if-it-is-not-a-decimal-or-integer-number%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

                                SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현