- 2026-07-23 1.1.22 Mejora de rutinas de validación de emails

This commit is contained in:
2026-07-23 14:57:09 +02:00
parent 4795f9b68f
commit 1f2d5e39d8
2 changed files with 7 additions and 10 deletions

View File

@@ -42,9 +42,10 @@ Namespace Extensiones
<Extension()>
Public Function EsEmailValido(ByVal email As String) As Boolean
Try
email = email.NothingAVacio.Trim.ToLower
Dim addr = New System.Net.Mail.MailAddress(email)
Return addr.Address = email
If String.IsNullOrWhiteSpace(email) Then Return False
Dim patron As String = "^(?("")("".+?""@)|(([0-9A-Za-z]((\.|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*[0-9A-Za-z])?)))" &
"@(([0-9A-Za-z]([-\w]*[0-9A-Za-z])?\.)+[A-Za-z]{2,})$"
Return Regex.IsMatch(email, patron)
Catch ex As Exception
Return False
End Try
@@ -58,12 +59,7 @@ Namespace Extensiones
Dim emails = Listaemail.Split(";")
For Each email In emails
email = email.NothingAVacio.Trim.ToLower
If email <> "" Then
Dim addr = New System.Net.Mail.MailAddress(email)
If addr.Address <> email Then
Throw New Exception("Email incorrecto")
End If
End If
If EsEmailValido(email) = False Then Return False
Next
Return True
End If