<script type="text/javascript">
function PasswordValidator() {
var passwordvalid = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])$/;
var passwordstrength = document.getElementById("<%=txtPassword.ClientID%>");
if (passwordstrength != passwordvalid)
{
alert("Password must contain at least 1 capital letter,\n\n1 small letter, 1 number and 1 special character.\n\nFor special characters you can pick one of these -,(,!,@,#,$,),%,<,>");
return false;
}
}
</script>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="btnCheck" runat="server" OnClientClick="PasswordValidator()" position: absolute; width: 90px;" Text="Check" />
Hi guys,
I was trying to create a function, which would check if the value inside txtPassword meets the password regex requirement. When a button is clicked and if the value fails, it would pop the alertbox shown. So I entered Will123! as a password to test it and the alertbox came up. “W” is capital letter. Could you please tell me what is wrong with the function. I need the alertbox to pop only if the password doesn’t meet the regex.
Thank you for your time.