Ronok Bhowmik

Ronok Bhowmik

  • NA
  • 37
  • 30k

Validate TextBox using regex where 1st input is alphabet

Feb 20 2014 2:13 PM
I have a textbox.I want to validate this textbox where i wish to enter the 1st letter as an alphabet and then numeric value(from 0 to 9). As say i want the input as F1,then how can i implement this sort of problem.Please help me to do so.I use a code but it donot works.
Here is my code:
***************************************************************
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox1.Text.Length == 0 )
{
MessageBox.Show("Please Enter your Phone No First", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
}
else if( else if (!Regex.IsMatch(textBox1.Text, @"^\[A-Z]\s[0-9]")))
{
MessageBox.Show("Data entry Successful", "Messsage", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
MessageBox.Show("Illegal entry", "Messsage", MessageBoxButton.OK, MessageBoxImage.Error);
}

Answers (3)