1.引用名称空间
using System.Text.RegularExpressions;
2.代码:
string strInput=" aaa@163.com";
string strExp=@"/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*"
// Create a new Regex object.
Regex r = new Regex(strExp);
// Find a single match in the string.
Match m = r.Match(strInput);
if (m.Success)
{
MessageBox.Show("验证成功!");
}
using System.Text.RegularExpressions;
2.代码:
string strInput=" aaa@163.com";
string strExp=@"/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*"
// Create a new Regex object.
Regex r = new Regex(strExp);
// Find a single match in the string.
Match m = r.Match(strInput);
if (m.Success)
{
MessageBox.Show("验证成功!");
}
博客介绍了在C#中使用正则表达式验证邮箱的方法。首先引用System.Text.RegularExpressions名称空间,然后定义邮箱字符串和正则表达式,创建Regex对象进行匹配,若匹配成功则弹出验证成功的提示框。
355

被折叠的 条评论
为什么被折叠?



