Función: IsEmailValid

Aqui les presento una función que siempre hace falta y (en mi caso) nunca tengo a mano.

Un función para validar direcciones de EMail.

Public Function IsEmailValid(ByVal sEmail As String) As Boolean

    Dim sEmailRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"

    Dim oRegex As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(sEmailRegex)

    If Not (oRegex.IsMatch(sEmail)) Then

    Return False

    Else

    Return True

    End If

End Function

En su versión C# quedaría así;

public bool IsEmailValid(string sEmail)

{

 string sEmailRegex = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";

 System.Text.RegularExpressions.Regex oRegex = new System.Text.RegularExpressions.Regex(sEmailRegex);

 if (!((oRegex.IsMatch(sEmail)))) {

   return false;

 } else {

   return true;

 }

}

Saludos y espero que les sea ta útil como a mi.

PD: La función original la obtuve de un CodeSnippet para VS2003 de desde CodeXChange. Les aconsejo este AddIn para Vs2003 ya que se encuentran cosas muy interesantes,

10 thoughts on “Función: IsEmailValid”

  1. Muy buena, modificando un poco ( casi toda) la expresion regular podes llegar a validar cualquier cosa.Slds

    Like

  2. yes … you are right.Y modificando un poco mas la funcion, los parametros, el codigo de la misma y la clase que la contiene, me puedo hacer cualquier cosa no ?:Pjejeje … un poco de cachondeo 😛

    Like

  3. Muy útil. Las regex siempre fueron una zona oscura para mí ;-).Ahh, otra cosa, muy bueno el artículo sobre como crear directorios virtuales en El Guille. Ya fuiste votado ;P

    Like

  4. Como alternativa, el método "IsMatch" puede encontrarse en la clase Regex como estático, por lo que no necesariamente se requiere instanciar un objeto oRegex. Simplemente se especifican el input y el pattern en Regex.IsMatch(..)C#:if (Regex.IsMatch(sEmail, sEmailRegex)) return true;else return false;(de paso le quito la negación, que es redundante ya que puedo invertir los valores de returno)

    Like

  5. Fe de erratas:En el comentario anterior, donde dice "valores de returno" quise decir "valores de retorno" ;)También habría que incluir el using System.Text.RegularExpressions;

    Like

  6. wow gold!All wow gold US Server 24.99$/1000G on sell! Cheap wow gold,wow gold,wow gold,Buy Cheapest/Safe/Fast WoW US EU wow gold Power leveling wow gold from the time you wWorld of Warcraft gold ordered!

    wow power leveling wow power leveling power leveling wow power leveling wow powerleveling wow power levelingcheap wow power leveling wow power leveling buy wow power leveling wow power leveling buy power leveling wow power leveling cheap power leveling wow power leveling wow power leveling wow power leveling wow powerleveling wow power leveling power leveling wow power leveling wow powerleveling wow power leveling buy rolex cheap rolex wow gold wow gold wow gold wow gold -49655267268151

    Like

  7. Hi,Do you have used LCDs, used flat screens and secondhand LCDs? Please go here:www.sstar-hk.com(Southern Stars).We are constantly buying re-usable LCD panels and working for LCD recycling.The re-usable panels go through strictly designed process of categorizing, checking, testing, repairing and refurbishing before they are re-used to make remanufactured LCD displays and TV sets.Due to our recent breakthrough in testing and repairing technology of LCD, we can improve the value for your LCD panels.
    Contact Us
    E-mail:sstar@netvigator.com
    website:www.sstar-hk.com[daigcabfhcadgg]

    Like

  8. Hi,Do you need advertising displays, advertisement screens, LCD digital signage and LCD signages? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[bjgfiagggjecjb]

    Like

  9. Hi,Do you need digital signages, advertising displays, digital sign, advertisement displays and advertising players? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[hdcheigaaafbi]

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.