How can I check these double Regex











up vote
0
down vote

favorite












I want to check if a phone number has 8 digits and doesn't start with zero. I used this pattern ^[1-9][0-9]{7} for this purpose, also I wanna check that these 8 numbers are not duplicated completely like 11111111 or 77777777, for which I use this pattern: (w)1{7,}, separately to check that the number doesn't match with it.



Now I want to combine these Regex patterns together but I can't. I try to combine these patterns in this way:
(?=([1-9][0-9]{7}))(?:(?!(w1{7,}))) but unfortunately it doesn't work.



Note that I have to use one Regex pattern and need to combine these two patterns into one.



Could anyone help me please?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I want to check if a phone number has 8 digits and doesn't start with zero. I used this pattern ^[1-9][0-9]{7} for this purpose, also I wanna check that these 8 numbers are not duplicated completely like 11111111 or 77777777, for which I use this pattern: (w)1{7,}, separately to check that the number doesn't match with it.



    Now I want to combine these Regex patterns together but I can't. I try to combine these patterns in this way:
    (?=([1-9][0-9]{7}))(?:(?!(w1{7,}))) but unfortunately it doesn't work.



    Note that I have to use one Regex pattern and need to combine these two patterns into one.



    Could anyone help me please?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to check if a phone number has 8 digits and doesn't start with zero. I used this pattern ^[1-9][0-9]{7} for this purpose, also I wanna check that these 8 numbers are not duplicated completely like 11111111 or 77777777, for which I use this pattern: (w)1{7,}, separately to check that the number doesn't match with it.



      Now I want to combine these Regex patterns together but I can't. I try to combine these patterns in this way:
      (?=([1-9][0-9]{7}))(?:(?!(w1{7,}))) but unfortunately it doesn't work.



      Note that I have to use one Regex pattern and need to combine these two patterns into one.



      Could anyone help me please?










      share|improve this question















      I want to check if a phone number has 8 digits and doesn't start with zero. I used this pattern ^[1-9][0-9]{7} for this purpose, also I wanna check that these 8 numbers are not duplicated completely like 11111111 or 77777777, for which I use this pattern: (w)1{7,}, separately to check that the number doesn't match with it.



      Now I want to combine these Regex patterns together but I can't. I try to combine these patterns in this way:
      (?=([1-9][0-9]{7}))(?:(?!(w1{7,}))) but unfortunately it doesn't work.



      Note that I have to use one Regex pattern and need to combine these two patterns into one.



      Could anyone help me please?







      javascript c# regex string validation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 8:25









      ProgrammerPer

      411511




      411511










      asked Nov 11 at 7:53









      msitworld

      278




      278
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          It's only the first character you need to check, it looks like - capture it in a group, then use negative lookahead for that group repeated 7 times, to ensure that the entire string is not all the same number, then finish with d{7} to match the other 7 digits:



          ^([1-9])(?!1{7})d{7}$


          https://regex101.com/r/DbTtAJ/1



          (note that [0-9] simplifies to d)






          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',
            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%2f53246818%2fhow-can-i-check-these-double-regex%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            6
            down vote



            accepted










            It's only the first character you need to check, it looks like - capture it in a group, then use negative lookahead for that group repeated 7 times, to ensure that the entire string is not all the same number, then finish with d{7} to match the other 7 digits:



            ^([1-9])(?!1{7})d{7}$


            https://regex101.com/r/DbTtAJ/1



            (note that [0-9] simplifies to d)






            share|improve this answer

























              up vote
              6
              down vote



              accepted










              It's only the first character you need to check, it looks like - capture it in a group, then use negative lookahead for that group repeated 7 times, to ensure that the entire string is not all the same number, then finish with d{7} to match the other 7 digits:



              ^([1-9])(?!1{7})d{7}$


              https://regex101.com/r/DbTtAJ/1



              (note that [0-9] simplifies to d)






              share|improve this answer























                up vote
                6
                down vote



                accepted







                up vote
                6
                down vote



                accepted






                It's only the first character you need to check, it looks like - capture it in a group, then use negative lookahead for that group repeated 7 times, to ensure that the entire string is not all the same number, then finish with d{7} to match the other 7 digits:



                ^([1-9])(?!1{7})d{7}$


                https://regex101.com/r/DbTtAJ/1



                (note that [0-9] simplifies to d)






                share|improve this answer












                It's only the first character you need to check, it looks like - capture it in a group, then use negative lookahead for that group repeated 7 times, to ensure that the entire string is not all the same number, then finish with d{7} to match the other 7 digits:



                ^([1-9])(?!1{7})d{7}$


                https://regex101.com/r/DbTtAJ/1



                (note that [0-9] simplifies to d)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 7:56









                CertainPerformance

                67.9k143353




                67.9k143353






























                    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%2f53246818%2fhow-can-i-check-these-double-regex%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

                    Full-time equivalent

                    Bicuculline

                    さくらももこ