Question: Is there any property or any function is giving which is prevent above issue..

i made a one register form.. and my friend inserted tag into username.. and it will raise a error at server side.. i tried to prevent it. with validation but.. it cant..

i did it.. check out this line.. 

```
txt_countryname.Text = HttpUtility.HtmlEncode(txt_countryname.Text);

```

but its not working ... – Sikender 0 secs ago [delete this comment]

help me...

Answer: 
you also can use asp:RegularExpressionValidator
Example:

```
<asp:TextBox ID="txt_username" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Text="Error" ErrorMessage="some error message" ValidationExpression="^[a-zA-Z0-9]+[a-zA-Z0-9]{4,15}$" SetFocusOnError="True" ControlToValidate="txt_username">

```
Server.HtmlEncode