110,566
社区成员
发帖
与我相关
我的任务
分享
string judgepwd = this.txt_NewPwd.Text.Trim();
if (judgepwd.Length < 6)
{
MessageBox.Show("密码必须大于6位");
this.txt_NewPwd.Text = "";
this.txt_AgeinNewPwd.Text = "";
return;
}
if (this.txt_NewPwd.Text != this.txt_AgeinNewPwd.Text)
{
MessageBox.Show("两次密码输入不一致");
this.txt_NewPwd.Text = "";
this.txt_AgeinNewPwd.Text = "";
return;
}
string papwd = (@"[a-zA-Z0-9]");
Regex reg = new Regex(papwd);
Match mc = reg.Match(judgepwd);
if (!mc.Success)
{
MessageBox.Show("密码必须为数字加字母的组合");
this.txt_NewPwd.Text = "";
this.txt_AgeinNewPwd.Text = "";
return;
}
public bool isEqual(string value1, string value2)
{
return value1 == value2;
}
调用:
if (!isEqual(this.txt_NewPwd.Text ,this.txt_AgeinNewPwd.Text))
像, string papwd = (@"[a-zA-Z0-9]");
Regex reg = new Regex(papwd);
Match mc = reg.Match(judgepwd);
这种代码,封装成一个方法,返回true或者false 直接传入值 判断就行了。
其实 你的那种方式也挺直观的。