I have a requirement to validate a field. The field should be numeric, should not contain all the same digits (like 555555, 111111) and the length is 6 chars. I need a regular expression to check this. I used [1-9] to check if it's numeric. Now I need to know how can I check if it contains all same digits.
Now I would like to use a single regex instead of the above 2. Can you please provide that?
I was hoping that when I showed you the solution, that you would be so wowed with regexes, that you would go out and figure out how it worked. And in doing so, learn other cool features of regexes. Cool features that does exactly what you want here.
If you really want to merge the two regexes. Take a look at the "zero width positive/negative lookahead" features.
Deepa Mj wrote:I need a regular expression to check this.
Why do you think you need a regex for this? Perhaps if you knew and loved regex, it would make sense. But a trivial for() loop with a test of each character would work, in all chances, be no slower, and would be a lot easier for someone else to undersand and maintain.