Skip to content

Commit 2a09ef9

Browse files
Refactor email validation to use InternetAddress
Replaced custom email regex validation with Jakarta Mail's InternetAddress validation in VUser. Removed the EMAIL_PATTERN constant from UserRegex as it is no longer needed.
1 parent afe41fb commit 2a09ef9

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/main/java/smartpot/com/api/Users/Validator/UserRegex.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@ public class UserRegex {
2727
*/
2828
public static final String LASTNAME_PATTERN = "^[a-zA-ZÁ-Úá-ú]{4,30}$";
2929

30-
/**
31-
* Expresión regular para validar la dirección de correo electrónico de un usuario.
32-
* <p>
33-
* El correo electrónico debe seguir el formato estándar: algo@dominio.com.
34-
* No se permiten espacios y debe haber un solo carácter '@' separando el nombre del dominio.
35-
* </p>
36-
*/
37-
public static final String EMAIL_PATTERN = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,}$";
38-
3930
/**
4031
* Expresión regular para validar la contraseña de un usuario.
4132
* <p>

src/main/java/smartpot/com/api/Users/Validator/VUser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package smartpot.com.api.Users.Validator;
22

3+
import jakarta.mail.internet.AddressException;
4+
import jakarta.mail.internet.InternetAddress;
35
import org.bson.types.ObjectId;
46
import org.springframework.stereotype.Component;
57
import smartpot.com.api.Users.Model.Entity.UserRole;
@@ -137,7 +139,9 @@ public void validateLastname(String lastname) {
137139
*/
138140
@Override
139141
public void validateEmail(String email) {
140-
if (email == null || !Pattern.matches(EMAIL_PATTERN, email)) {
142+
try {
143+
new InternetAddress(email).validate();
144+
} catch (AddressException e) {
141145
valid = false;
142146
errors.add("El correo electrónico no es válido");
143147
}

0 commit comments

Comments
 (0)