-1
Hello, I’m doing a Customer Registration system and I have a problem that I have no idea how to fix, I know it’s "simple" but I’m programming a little and I haven’t found any way that really works.
To register a customer there is the phone field where I did a treatment to organize the number, without mask.
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
this.BackColor = Color.White;
string TelCel;
TelCel = this.Text;
string result = TelCel;
{
if (TelCel.Length == 13)
{
this.Text = TelCel.Insert(0, "(").Insert(3, ")").Insert(9, "-");
}
if (TelCel.Length == 11)
{
this.Text = TelCel.Insert(0, "(").Insert(3, ")").Insert(9, "-");
}
if (TelCel.Length == 10)
{
this.Text = TelCel.Insert(0, "(").Insert(3, ")").Insert(8, "-");
}
{
if ((TelCel.Length != 11) && (TelCel.Length != 10))
{
this.Text = TelCel;
}
}
}
}
By typing the phone in his hand he’ll come out like this:
However when copying and pasting Whatsapp phone or other place it does not do the formatting:
However he enters the database in both ways, but if I want to make a query I can not due to Parentheses, I would like to know how to standardize the phone number, either in Ctrl+c, Ctrl+v or by typing the hand.
Thanks in advance for the help!
Is that Windows Forms? Ideally, use a mask component.
– Jéf Bueno