Priya M

Priya M

  • NA
  • 42
  • 11.4k

RegularExpression

Feb 4 2016 5:33 AM
Hello,
 
In text box i want to allow character,Number,Special Symbols like \ . ,-'
And also remove wrong character when i click on Messagebox.
 
Here is my code
private void txtPNo_TextChanged(object sender, TextChangedEventArgs e)
{
 
if (!System.Text.RegularExpressions.Regex.IsMatch(txtPNo.Text, "^[a-zA-Z0-9]*$"))
{
MessageBox.Show("This Textbox accepts only Alphabetes & Numeric Value");
txtPNo.Text.Remove(txtPNo.Text .Length -1);
}
////error
 txtPNo.Text.Remove(txtPNo.Text .Length -1);//This line could not return anything
if first character is wrong then  length is 0 and it causes error
 
 

Answers (1)