2

I need to validate a field with a fixed length of 8 and it only accept numbers, like 12345678 or 11111118 (these are valid).

But I cannot accept when all numbers are the same, like 11111111

I came with ^\d{8}(\1*)$ https://regex101.com/r/tH2hB7/1 , but I can´t find the correct pattern to identify the repeating numbers

1 Answer 1

4

You can add lookahead for the same. See demo.

^(\d)(?!\1{7}$)\d{7}$

https://regex101.com/r/tH2hB7/4

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.