32 lines
935 B
Java
32 lines
935 B
Java
package com.banesco.infraestructure.utils;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
/**
|
|
* Clase para validar números telefónicos según patrones específicos. Utiliza
|
|
* expresiones regulares para verificar que los números telefónicos cumplan con
|
|
* el formato esperado, permitiendo diferentes configuraciones según los
|
|
* requisitos regionales o de formato de la aplicación.
|
|
*/
|
|
public class PhoneNumberValidator {
|
|
|
|
private final Pattern pattern;
|
|
|
|
public PhoneNumberValidator(String phonePattern) {
|
|
pattern = Pattern.compile(phonePattern);
|
|
}
|
|
|
|
/**
|
|
* Validates the phone number format.
|
|
*
|
|
* @param phoneNumber the phone number to validate.
|
|
* @return true if the phone number is valid, false otherwise.
|
|
*/
|
|
public boolean isValid(String phoneNumber) {
|
|
if (phoneNumber == null) {
|
|
return false;
|
|
}
|
|
return pattern.matcher(phoneNumber).matches();
|
|
}
|
|
}
|