using System;
using System.Text.RegularExpressions;
class ValidateEmail
{
static void Main(string[] args){
string pattern = @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex regex = new Regex(pattern);
string emailName="email@email.com";
if (!regex.IsMatch(emailName))
{
print("邮件地址无效");
return;
}else{
print("邮件地址有效");
}
}
}
本文介绍了一种使用正则表达式验证电子邮件地址有效性的方法。通过C#代码实现,匹配常见的电子邮件格式,确保电子邮件地址符合标准规范。
331

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



