使用正则表达式验证邮箱格式
发布时间:2020-12-14 06:12:27 所属栏目:百科 来源:网络整理
导读:实现效果: 知识运用: (下图中好像多了个‘(‘ ) ? 实现代码: private void button1_Click(object sender,EventArgs e) { if (validate(textBox1.Text)) textBox1.BackColor = Color.Green; else textBox1.BackColor = Color.Red; } public bool validate(
实现效果: 知识运用:(下图中好像多了个‘(‘ ) ?实现代码: private void button1_Click(object sender,EventArgs e) { if (validate(textBox1.Text)) textBox1.BackColor = Color.Green; else textBox1.BackColor = Color.Red; } public bool validate(string str_email) { return System.Text.RegularExpressions.Regex. IsMatch(textBox1.Text,@"^(([w.]+)@([[0-9]{1,3}.[0-9]{1,3}])|((w+.?)+)@([a-zA-Z]{2,4}|[0-9]{1,3})(.[a-zA-Z]{2,4}))$"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |