Reputation: 6639
I am using an input filter and have used it to match the regex set in the xml.
So think of this regex that it will test each time the user presses a key in the keyboard.
These are what should match : "john", "john-ernest", "j10n", "jo199", "john-ernest1"
These should not : "-jon", "09john", "aaa", "aa", "john-"
Basically :
it should always start with an alphabet character(regardless of the case)
it can accept a '-' character but only once and it cannot be in the start or end position
it can accept numbers, but not in the start position
it cannot accept a character if the one before it is the same, so no repeating characters.
I got only up to this : ^[a-zA-Z]+[a-zA-Z0-9-]?[a-zA-Z0-9]*$
Any help would be greatly appreciated The problem with this, it does not accept a '-' character while typing because it only accepts it.
Upvotes: 0
Views: 70
Reputation: 174826
You may try the below lookahead based regex.
^(?!.*(.)\1)[a-zA-Z]+[a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*$
Upvotes: 1