private void TxtpaperID_Leave(object sender, EventArgs e) { if (cboPaper.Text == "身份证") { if (TxtpaperID.Text.Length != 18 && TxtpaperID.Text.Length != 0 && TxtpaperID.Text.Length != 15) { MessageBox.Show("身份证只能是18位或15位!", "温馨", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtpaperID.Focus(); TxtpaperID.SelectAll(); } } }
//验证是否为空 private bool ValidateInput() { bool isOk = true; if (TxtID.Text == "") { TxtID.BackColor = Color.Red; TxtID.Focus(); isOk = false; } if (Txtname.Text == "") { Txtname.BackColor = Color.Red; Txtname.Focus(); isOk = false; } if (Txtpwd.Text == "") { Txtpwd.BackColor = Color.Red; Txtpwd.Focus(); isOk = false; } if (txtAddress.Text == "") { txtAddress.BackColor = Color.Red; txtAddress.Focus(); isOk = false; } if (TxtpaperID.Text == "") { TxtpaperID.BackColor = Color.Red; TxtpaperID.Focus(); isOk = false; } if (TxtcontactTel.Text == "") { TxtcontactTel.BackColor = Color.Red; TxtcontactTel.Focus(); isOk = false; } return(isOk); //返回结果 }