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/