c# - 在 C# 后端检查正则表达式验证器的验证

标签 c# asp.net sql-server database ado.net

protected void UserId_TextBox_TextChanged(object sender, EventArgs e)
{
    SqlDataAdapter da = new SqlDataAdapter("select user_id from Userinfo where user_id='" + UserId_TextBox.Text + "@femail.com'", con);
    DataTable dt = new DataTable();
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        UserId_Label.Text = "Someone already has that username, try another?";
    }
    else 
    {
        UserId_Label.Text = "Wow , its a unique username! please fill in the remaining fields of the form";
    }

这是我用来检查用户是否已经存在的一段代码,我想在控件进入循环的其他部分之前检查我强加的正则表达式验证器文本框是否已验证...有人可以在这里提供帮助。 (我可以在 else 部分之前使用 else if 语句并检查正则表达式是否已通过某种方法验证吗?)

提前致谢。

最佳答案

您可以使用 ifelse 在 else 上验证文本框正则表达式验证

 if(dt.Rows.Count > 0)
{
    UserId_Label.Text = "Someone already has that username, try another?";
}
elseif(!Page.IsValid)
{
    // Do what needs to be done when not valid
    UserId_Label.Text = "Invalid username input";
}
else
{
    UserId_Label.Text = "Wow , its a unique username! please fill in the remaining fields of the form";
}

关于c# - 在 C# 后端检查正则表达式验证器的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19428096/

相关文章:

C# 泛型/接口(interface) - 根据类返回不同类型

asp.net - 使用 App_GlobalResources 在 ASP.NET MVC 4 中进行本地化

c# - 如何根据文本框中的姓名填充数据库中某个人的所有记录?

c# - 后台 worker 不工作

c# - 对我的自定义成员(member)资格提供商进行单元测试

c# - 在RelativeLayout中动态绑定(bind)多个图像与MVVM?

c# - 如何在 JavaScript 中将 ID 设置为动态创建的文本框

c# - ASP.NET MVC : how to make all unspecified URLs direct to one controller

sql-server - SQL Server 2005 - 无法绑定(bind)多部分标识符

sql-server - 为什么在这种情况下忽略 ConnectTimeout?