【问题标题】:how to check if email is in valid format or not in c#如何在c#中检查电子邮件的格式是否有效
【发布时间】:2017-06-06 07:47:38
【问题描述】:

我的代码是任何人都可以纠正此问题或解决此问题的任何其他解决方案。 这是我到目前为止所得到的,但它似乎不起作用:

  int i=0,f=0;
    string n = Console.ReadLine();
    for (i = 0; i < n.Length; i++)          
        if(n[i]=='@' || n[i] == '.')              
            f = f + 1;               
    if(f==2){
console.writeline('correct')
}
    else{
console.writeline('Incorrect') 

【问题讨论】:

标签: c# asp.net .net xcode email-validation


【解决方案1】:

试试这个:

using System.ComponentModel.DataAnnotations;
public bool IsValidEmail(string email)
 {
    return new EmailAddressAttribute().IsValid(email);
 }

【讨论】:

  • 正则表达式不是根据this answer验证电子邮件地址的好方法。
猜你喜欢
  • 1970-01-01
  • 2015-08-07
  • 2011-10-07
  • 2018-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-18
  • 2017-01-14
相关资源
最近更新 更多