I'd like to provide users with a fancy license key textbox, that would insert the dashes. The key is supposed to be 20 characters long ( 4 groups of 5 characters )
I tried using regex, first:
Regex.Replace( text, ".{5}", "$0-" );
that is a problem as the dash is inserted even when there's no following characters, e.g AAAAA-, that results in not being able to remove the dash as it's automatically re-inserted.
then I thought about telling the regex there should be a following character
Regex.Replace( text, "(.{5})(.)", "$1-$2" );
but that splits the key into group of 5-6-6...
Any ideas?