我有一个服务器端 customvalidator。因为它没有触发,所以我想使用客户端来验证一个文本框。它包括活动目录的东西。我不确定我们可以将代码转换为客户端吗?
<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>
和
protected void ValidateUser(object source, ServerValidateEventArgs args)
{
string UserNameCreated = TextUserName.Text;
string AD_Server = System.Configuration.ConfigurationManager.AppSettings["AD_Server"];
DirectoryEntry entry = new DirectoryEntry(AD_Server);
entry.AuthenticationType = AuthenticationTypes.Secure;
DirectorySearcher deSearch = new DirectorySearcher(entry);
deSearch.Filter = "(&(objectClass=user)(samaccountname=" + UserNameCreated + "))";
SearchResultCollection results = deSearch.FindAll();
Match match = Regex.Match(args.Value, @"^[a-zA-Z0-9]{6,}$",
RegexOptions.IgnoreCase);
if (results.Count > 0)
args.IsValid = false;
else if (match.Success)
args.IsValid = true;
// true means that it is validated.
else
args.IsValid = false;
}
我的想法:
拳头:
<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."
ClientValidatationFunction="ValidateUser" Display="Dynamic"
ValidateEmptyText="True" ></asp:CustomValidator></td>
第二
<script language="javascript">
function ValidateUser(source, arguments)
{
var RegularExpression = /^[a-zA-Z0-9]{6,}$/;
if (arguments.Value.test(RegularExpression) == 0 ){
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
</script>
那么AD呢?也许这是一个错误的问题!
谢谢。