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上验证textbox正则表达式验证

 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/

10-09 18:20
查看更多