邮箱及密码的正则表达式验证(C#)
2008-09-26 22:26
302 查看
刚接触正则表达式,发现其功能竟然如此的“很好很强大”,于是用C#写了一个邮箱的验证,小弟菜菜,如有不足之处敬请指出,同时也希望对刚接触正则表达式的兄弟姐妹有所帮助! 下面是代码部分:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace RegulatorTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnTest_Click(object sender, EventArgs e)
{
//验证 E-mail 格式
string regexEmail = "\\w{1,}@\\w{1,}\\.\\w{1,}";
System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
| System.Text.RegularExpressions.RegexOptions.Multiline)
| System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regEmail = new System.Text.RegularExpressions.Regex(regexEmail, options);
string email = txtEmail.Text;
if (regEmail.IsMatch(email))//email 填写符合正则表达式 "\\w{1,}@\\w{1,}\\.\\w{1,}"
{
MessageBox.Show("符合正则表达式:"+regEmail.ToString()+"\n邮箱填写成功!");
}
else {
MessageBox.Show("不符合正则表达式:"+regEmail.ToString()+"\n邮箱格式不正确!");
return;
}
//验证密码 由不小于6位不大于15位的字母数字下划线特殊符号组成!
string regexPwd = "^.{6,15}___FCKpd___0quot;;//限定开头,须从第一位开始匹配,限定结尾,总位数不得超过15位,否则即使大于15位仍然可以验证通过
System.Text.RegularExpressions.Regex regPwd = new System.Text.RegularExpressions.Regex(regexPwd, options);
string pwd = txtPwd.Text;
if (regPwd.IsMatch(pwd))
{
MessageBox.Show("符合正则表达式:"+regPwd.ToString()+"\n密码验证通过!");
}
else {
MessageBox.Show("不符合正则表达式:"+regPwd.ToString()+"\n密码验证失败!密码应由不小于6位不大于15位的字母数字下划线特殊符号组成!");
return;
}
}
}
}
本文出自 “cndo” 博客,请务必保留此出处http://51cndo.blog.51cto.com/491222/102326
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace RegulatorTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnTest_Click(object sender, EventArgs e)
{
//验证 E-mail 格式
string regexEmail = "\\w{1,}@\\w{1,}\\.\\w{1,}";
System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
| System.Text.RegularExpressions.RegexOptions.Multiline)
| System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regEmail = new System.Text.RegularExpressions.Regex(regexEmail, options);
string email = txtEmail.Text;
if (regEmail.IsMatch(email))//email 填写符合正则表达式 "\\w{1,}@\\w{1,}\\.\\w{1,}"
{
MessageBox.Show("符合正则表达式:"+regEmail.ToString()+"\n邮箱填写成功!");
}
else {
MessageBox.Show("不符合正则表达式:"+regEmail.ToString()+"\n邮箱格式不正确!");
return;
}
//验证密码 由不小于6位不大于15位的字母数字下划线特殊符号组成!
string regexPwd = "^.{6,15}___FCKpd___0quot;;//限定开头,须从第一位开始匹配,限定结尾,总位数不得超过15位,否则即使大于15位仍然可以验证通过
System.Text.RegularExpressions.Regex regPwd = new System.Text.RegularExpressions.Regex(regexPwd, options);
string pwd = txtPwd.Text;
if (regPwd.IsMatch(pwd))
{
MessageBox.Show("符合正则表达式:"+regPwd.ToString()+"\n密码验证通过!");
}
else {
MessageBox.Show("不符合正则表达式:"+regPwd.ToString()+"\n密码验证失败!密码应由不小于6位不大于15位的字母数字下划线特殊符号组成!");
return;
}
}
}
}
本文出自 “cndo” 博客,请务必保留此出处http://51cndo.blog.51cto.com/491222/102326
相关文章推荐
- 邮箱及密码的正则表达式验证(C#)
- 邮箱及密码的正则表达式验证(C#)
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码
- iOS 开发: 用户名、邮箱、电话号码、密码、昵称正则表达式验证
- iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证
- C#中使用正则表达式验证电话号码、手机号、身份证号、数字、邮编、时间(仅年月日)、邮箱、小数的正则表达式
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- js验证 正则表达式 包含手机号码、座机号码、电子邮箱、密码、姓名、身份证号码等表单数据的验证
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- 使用正则表达式验证注册页面(用户名,密码,确认密码,邮箱,手机号)
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码
- [转]C#代码实现邮箱验证C#中及一些常用的正则表达式
- iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证
- iOS开发中邮箱,电话号码,身份证,密码,昵称正则表达式验证
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- jQuery 找回密码三步验证邮箱正则表达式 验证手机 获取验证码倒计时 php版
- 使用js和正则表达式验证邮箱、手机号码、密码等
- C#验证:正则表达式 验证类和界面处理(手机号码,邮箱,IP地址)
- JS 正则表达式验证密码、邮箱格式的实例代码
- 使用 jQuery 验证密码一致性,正则表达式验证邮箱及手机号的方法