Showing posts with label Regular expression to avoid special characters. Show all posts
Showing posts with label Regular expression to avoid special characters. Show all posts

Monday, 28 April 2014

Regular expression to avoid special characters

private bool IsValidName(string strtxt)
{
bool returnValue = false;
Regex regx = new Regex(@"^[\w\s -]*$");
returnValue = regx.IsMatch(strtxt);
return returnValue;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!IsValidName(txtA.Text))
{
Response.Write("Entered Special Charectors-Not correct name");
}
else
{
Response.Write(txtA.Text);
}
}