1
Answer

RegularExpression

Priya M

Priya M

9y
715
1
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)