asp.net - C# Validating a password on SERVER SIDE -
i'm right trying validate password on server side using .net
here's client side code:
<asp:textbox id="pswrd" runat="server" width="120px"></asp:textbox> <span style="background-color:yellow; color:red; font-weight:bold;" title="some rules">password rules</span> <asp:requiredfieldvalidator id="vpswrd" runat="server" errormessage="a password required" controltovalidate="pswrd"> </asp:requiredfieldvalidator> <asp:customvalidator id="ipswrdval" runat="server" onservervalidate="validatepasswordserverside" controltovalidate="pswrd" errormessage="please enter *valid* password" validateemptytext="false" ></asp:customvalidator>
my first validator works fine. displays it's message when appropriate.
the second 1 gives me trouble.
here's code behind
protected void validatepasswordserverside(object source, servervalidateeventargs args) { if (regex.ismatch(args.value, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")) args.isvalid = true; else args.isvalid = false; }
the issue i'm not seeing error message display second validator whenever enter incorrect value.
also little plea, before people exotic solutions please note school assignment, want cookie cutter approach. know, it's dumb rules rules.
it bad think call server side method check password validate.
use
<asp:regularexpressionvalidator runat="server" id="rgpassvalide" errormessage="please enter *valid* password" controltovalidate="pswrd" validationexpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"></asp:regularexpressionvalidator>
insted of "asp:customvalidator".
above code helps make working.
Comments
Post a Comment