Ok, the OnValueChange, as I was searching about it, seems to still have many flaws as not seeing Ctrl+Vs, Ctrl+X, backspaces, it doesn’t seem to actually check every condition, but ok for now. My problem is that I can’t seem to mask format the data as the user writes it.
Took me about a day looking for answers to find out that every single one I found telling me to change the text was wrong, that I had to change the text from InputField. It works on onEndEdit, but doesn’t work on onValueChanged.
So I wanted to know if anyone know a workaround this.
Well, for those who want to know what I am doing:
public void FormatTel(UnityEngine.UI.InputField IFD_Telefone)
{
IFD_Telefone = FormatWithMask(IFD_Telefone.text, "(##) ####-####");
}
public string FormatWithMask(string input, string mask)
{
if (string.IsNullOrEmpty(input)) return input;
var output = string.Empty;
var index = 0;
foreach (var m in mask)
{
if (m == '#')
{
if (index < input.Length)
{
output += input[index];
index++;
}
}
else
output += m;
}
return output;
}
I call the FormatTel from the onValueChanged from IFD_Telefone. That gives me a Null Reference Exception, need a workaround to change the values for that format shown above.