写的一个判断注册Email是否是个人邮件,而不是公司邮件的方法

以下这个方法其实也不是很全面,它只判断了hotmail, gmail和yahoo

如果你还需要加上其他认为是私人Email的Email, 只要按照同样的方法自己加上就可以了

 

复制代码
    Public void CheckPersonalEmail(ByVal sender As Object, ByVal email As ServerValidateEventArgs)
    {
            string strEmail = email.Value.ToLower;
          
            var r = New Regex("([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$", RegexOptions.IgnoreCase);
            
            if((strEmail <> "") And (strEmail.IndexOf("hotmail") = -1) And (strEmail.IndexOf("gmail") = -1) And (strEmail.IndexOf("yahoo") = -1) And (r.Match(strEmail).Success))
             email.IsValid = true
            
            if  (!email.IsValid) 
            {
                If (strEmail = "") 
                      CustomValidator1.ErrorMessage = "<br />Please enter an email address"
  
                If ((strEmail.IndexOf("hotmail") > -1) Or (strEmail.IndexOf("yahoo") > -1) Or (strEmail.IndexOf("gmail") > -1)) 
                    CustomValidator1.ErrorMessage = "<br />You cannot use a personal email address"

               
                If  (!r.Match(strEmail).Success) 
                     CustomValidator1.ErrorMessage = "<br />You must enter a valid email address"
            }

     }
    
复制代码

基于vb.net我自己改写的,可能有的地方语法不正确,自己在Visual Studio中更改就好

posted on   新西兰程序员  阅读(438)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示