I need to ensure that a input string follows these rules:
- It should contain upper case characters only.
- NO character should be repeated in the string.
eg. ABCA is not valid because ‘A’ is being repeated.
For the upper case thing, [A-Z] should be fine.
But i am lost at how to ensure no repeating characters.
Can someone suggest some method using regular expressions ?
You can do this with .NET regular expressions although I would advise against it:
Instead I’d advise checking that the length of the string is the same as the number of distinct characters, and checking the A-Z requirement separately:
Alteranatively, if performance is a critical issue, iterate over the characters one by one and keep a record of which you have seen.