The problem is that the dashes are not inserted again after a user deletes or retypes part of a serial key.
Hello, I am working on formatting a license key that lives updates within a TMP_InputField in Unity. When the user is typing a dash should be automatically added after every digits. To be clear I was able to do this however can't get it so when you delete everything and put it in again the dashes should appear. This isn my Start() function has been added as an EventListener to onValueChanged however my suspicion is there is something to do with the length so if anyone could help me that would be great thank you so much?
void addDashes(string licenseKey)
{
int charPos = licenseKey.Length;
if ((charPos - dashNum) != 0 && (charPos - dashNum)%5 == 0 && licensingField.text.ToString() != "_" && dashNum < 3)
{
licensingField.text += "-";
dashNum++;
}
}
For anyone interested this took me a long time to find anything online about but this works for the adding a dash dynamically every 5 spots and can be deleted etc. Hope this helps your search