Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all
I am facing the problem that is I want to give a message when the user types other than the mobile series (mobile series like 9, 7, 8) windows application C#.NET.
First number should be the 9 or 7 or 8 other I should give the message.
Here mobile1txt is the TextBox name.
Please check and correct it.
C#
private void mobile1txt_KeyPress(object sender, KeyPressEventArgs e)
{
    if (mobile1txt.Text.StartsWith("9") || mobile1txt.Text.StartsWith("8") || mobile1txt.Text.StartsWith("7"))
    {
    }
    else
    {
        MessageBox.Show("Mobile number should start with 9, 8 or 7 only", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        e.Handled = true;
        mobile1txt.Focus();
    }
}
Posted
Updated 12-Aug-10 21:50pm
v4

1 solution

The KeyPress event happens when you press the key. It means the mobile1txt.Text is still empty (you can set a breakpoint and check it).

You can try the KeyUp event.
 
Share this answer
 
Comments
[no name] 13-Aug-10 4:34am    
Reason for my vote of 5
perfect one

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900