I am making a phone number form. The mask is +7(***)***-**-**. I am trying to make a custom TMP_Validator for this. The input still should look like +7(9**)***-**-**, +7(99*)***-**-** and so on.
What I have so far:
public override char Validate(ref string text, ref int pos, char ch)
{
if (ch == '\b')
{
return ch;
}
string numericText = new String(text.Where(c => char.IsDigit(c)).ToArray());
if (numericText.Length < 11)
{
string proposedText = text.Substring(0, text.Length) + ch;
if (Regex.IsMatch(proposedText, @"^\d{10}$"))
{
text = FormatPhoneNumber(proposedText);
pos++;
return ch;
}
}
return '\0';
}
But that does not work. Brain is melting, so I am here for your help.