We know usually the CustomValidator control will check the user's input against some arithmetic validation.
I have a textbox in my web form. The text of it doesn't come from user's input, it comes from the database.
MembershipUser user = Membership.Providers["SqlMembershipProvider"].GetUser(userName);
TextUserName.Text = AntiXss.HtmlEncode(user.UserName);
My goal is to use some kind of validator to check whether it is appropriate. If not then change it in the textbox and validate it again. How to do it?
Thanks.
UPDATE CODE:
protected void ValidateUser()
{
string UserNameCreated = TextUserName.Text;
Match match = Regex.Match(UserNameCreated, @"^[a-zA-Z0-9]{6,}$",
RegexOptions.IgnoreCase);
}
<td class="style4">
<asp:TextBox ID="TextUserName" runat="server"></asp:TextBox>
</td><td><asp:CustomValidator ID="CustomValidatorUser" runat="server" ControlToValidate="TextUserName"
ErrorMessage="Minimum of 6 (six) alphanumeric characters."
OnServerValidate="ValidateUser" Display="Dynamic"
ValidateEmptyText="True" ></asp:CustomValidator></td>