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?
javascript c# regex string validation
add a comment |
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?
javascript c# regex string validation
add a comment |
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?
javascript c# regex string validation
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
javascript c# regex string validation
edited Nov 11 at 8:25
ProgrammerPer
411511
411511
asked Nov 11 at 7:53
msitworld
278
278
add a comment |
add a comment |
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
)
add a comment |
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
)
add a comment |
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
)
add a comment |
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
)
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
)
answered Nov 11 at 7:56
CertainPerformance
67.9k143353
67.9k143353
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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