Bu makale, bir E-posta adresinin normal ifadelerle doğrulanması konusunu tartışır ve son olarak bir C # çalışan örnek proje sunar.
Neredeyse tüm durumlarda, birçok nedenden dolayı (yani, verilen şablonun kanıtı olarak güvenlik, güvenilirlik, vb.) Kullanıcı girişini doğrulamak iyi bir uygulamadır. Bu durumlardan biri oldukça yaygın bir e-posta doğrulaması durumudur. Bu makale bu konuyu biraz tartışıyor ve verilen e-posta doğrulama görevi için “kullanıma hazır” bir çözüm olarak uygulanabilecek çok basit bir C# statik sınıfı sunuyor.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | // Öncelikle Düzenli İfadeleri sisteme tanıtıyoruz using System.Text.RegularExpressions; public Boolean fnE_Posta_Mi(String parE_Posta) { Boolean blnDonen_Deger = false; if (String.IsNullOrEmpty(parE_Posta) == true) { blnDonen_Deger = false; } else { Regex desen = new Regex("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"); blnDonen_Deger = desen.IsMatch(parE_Posta); } return blnDonen_Deger; } public String fnE_Posta_Maskele(String parE_Posta) { String strDonen_Deger = ""; if (fnE_Posta_Mi(parE_Posta) == true) { String[] arrParcalar = parE_Posta.Split('@'); String strE_Posta = arrParcalar[0]; String strUzanti = arrParcalar[1]; if (strE_Posta.Length > 2) { for (Int32 i = 0; i < strE_Posta.Length; i++) { String strHarf = strE_Posta[i].ToString(); if (i > 0 && i < strE_Posta.Length - 1) { strDonen_Deger += strHarf.Replace(strHarf, "*"); } else { strDonen_Deger += strHarf; } } strDonen_Deger = strDonen_Deger + "@" + strUzanti; } else if (strE_Posta.Length == 2) { strE_Posta = strE_Posta.Replace(strE_Posta.Substring(1), "*"); strDonen_Deger = strE_Posta + "@" + strUzanti; } } return strDonen_Deger; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Örnek 1 (ASP.NET) String strE_Posta1 = "deneme@google.com"; String strE_Posta_Maskeli1 = fnE_Posta_Maskele(strE_Posta1); Response.Write(strE_Posta_Maskeli1); // Ekran Çıktısı: d****e@google.com; // Örnek 2 (ASP.NET) String strE_Posta2 = "matematik@google.com"; String strE_Posta_Maskeli2 = fnE_Posta_Maskele(strE_Posta2); Response.Write(strE_Posta_Maskeli2); // Ekran Çıktısı: m*******k@google.com ; // Örnek 3 String strE_Posta3 = "de@yahoo.com"; String strE_Posta_Maskeli3 = fnE_Posta_Maskele(strE_Posta3); MessageBox.Show(strE_Posta_Maskeli3); // Ekran Çıktısı: d*@yahoo.com ; |
Yorum Yap