Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用于在广告中添加用户并验证姓名/电子邮件的表单_C#_Javascript_Jquery_Asp.net_.net - Fatal编程技术网

C# 用于在广告中添加用户并验证姓名/电子邮件的表单

C# 用于在广告中添加用户并验证姓名/电子邮件的表单,c#,javascript,jquery,asp.net,.net,C#,Javascript,Jquery,Asp.net,.net,在我的页面中,我需要和表单在请求中添加用户。 我需要验证在活动目录中输入的此名称或电子邮件。 有人有一个表单(ASPX、HTML、Javascript)可以插入用户和C#来在广告中验证这个值吗 今天,它是我所拥有的,但从视觉上看,它是丑陋的,不能验证输入的内容 <asp:TextBox ID="txtUserAdd" runat="server" Height="17px" Width="150px"></asp:TextBox> <asp:Button I

在我的页面中,我需要和表单在请求中添加用户。 我需要验证在活动目录中输入的此名称或电子邮件。 有人有一个表单(ASPX、HTML、Javascript)可以插入用户和C#来在广告中验证这个值吗

今天,它是我所拥有的,但从视觉上看,它是丑陋的,不能验证输入的内容

<asp:TextBox ID="txtUserAdd" runat="server" Height="17px" Width="150px"></asp:TextBox>
    <asp:Button ID="btnAddUser" class="btn" runat="server" Font-Bold="true" Text="Add User" OnClick="btnSendUser_OnClick" />
    <br />
    <table id="tblUsers" CssClass="table table-bordered">
        <asp:Label ID="lblUser" runat="server" Visible="false"></asp:Label>
    </table>


protected void btnSendUser_OnClick(object sender, EventArgs e)
{
    lblUser.Visible = true;
    lblUser.Text = txtUserAdd.Text;
}


受保护的void btnSendUser\u OnClick(对象发送方,事件参数e) { lblUser.Visible=true; lblUser.Text=txtUserAdd.Text; }
虽然就我个人而言,我从未使用过活动目录,所以我假设“活动目录”与数据库一样。有关于MSDN的信息。目前,我有3种方法可以检查ASP.net应用程序中的身份验证

1。使用正则表达式

public class Test_Validation
{
  public bool Test_User(string username)
  {
  // Setup your username pattern
    const string pattern = @"^[a-z0-9_-]{3,15}$"/*NICE SAMPLE Username REGEX!*/;
    // check if the pattern matches
    if (System.Text.RegularExpressions.Regex.IsMatch(/*The string to check the pattern on*/username, /* the regular expression pattern */pattern, /* a flag for REGEX */ System.Text.RegularExpressions.RegexOptions.IgnoreCase))
    {
        System.Console.WriteLine("  (match for '{0}' found)", pattern);
    }
    else
    {
        System.Console.WriteLine("Sorry, no match found");
    }
  }
}
1+使用if/else语句并解析字符串,这似乎是非常冗长和不必要的解释。

2。使用jQuery验证。您可以在此网站上阅读jQuery验证:

3。使用数据注释属性 下面是一篇关于使用数据注释的好文章:


很抱歉,这里没有列出太多的代码示例,请询问我,我将非常乐意详细说明您希望继续使用哪种类型的验证(我个人将使用最后一个选项)

自定义验证程序服务器端

对于AD,使用System.DirectoryServices,我使用DirectorySearcher