Refer this one.
HTML
<div>
<asp:TextBox ID="txtPassword" runat="server" />
<asp:CheckBox ID="ChkComplexPass" runat="server" AutoPostBack="true" OnCheckedChanged="ChkComplexPassOnCheckedChanged" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="Required" ControlToValidate="txtPassword"
runat="server" ValidationGroup="usrvalid" />
<asp:RegularExpressionValidator ID="Regex4" runat="server" ControlToValidate="txtPassword"
ValidationExpression="^(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"
ErrorMessage="Password must contain atleast 1 UpperCase Alphabet, 1 Number and 1 Special Character"
ForeColor="Red" ValidationGroup="usrvalid" />
<br />
<asp:Button ID="Button1" Text="Save" OnClick="Save" runat="server" ValidationGroup="usrvalid" />
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.PasswordPolicy();
}
}
protected void ChkComplexPassOnCheckedChanged(object sender, EventArgs e)
{
if (this.ChkComplexPass.Checked)
{
this.Regex4.Enabled = true;
}
else
{
this.Regex4.Enabled = false;
}
}
private void PasswordPolicy()
{
if (this.ChkComplexPass.Checked)
{
this.Regex4.Enabled = true;
}
else
{
this.Regex4.Enabled = false;
}
}
protected void Save(object sender, EventArgs e)
{
string s = string.Empty;
}
You can also do it from Client Side
Refer