Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须按照代码验证电子邮件地址
var reg = new Regex(@"/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/"); string e1 = "name@host.net"; string e2 = "namehost.net"; bool b1 = reg.IsMatch(e1); bool b2 = reg.IsMatch(e2);
但b1和b2都失败了
删除开头和结尾的斜线。
var reg = new Regex(@"^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$");
但是,话虽如此,您的正则表达式并不是匹配电子邮件地址的好模式。事实上,准确的图案确实很难制作。谷歌一些,你应该找到更好的。