Skip to content

Instantly share code, notes, and snippets.

@ian-ellis
Last active January 16, 2017 22:33
Show Gist options
  • Save ian-ellis/92082e44f53f38e7e93e2a48cb44e075 to your computer and use it in GitHub Desktop.
Save ian-ellis/92082e44f53f38e7e93e2a48cb44e075 to your computer and use it in GitHub Desktop.
Validate Email Use Case
package com.theiconic.spockexamples.common.domain.usecases;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
public class ValidateEmailUseCase implements UseCase<String,Boolean> {
private static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
@Inject
public ValidateEmailUseCase() {
}
@Override
public Boolean execute(String emailStr) {
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr);
return matcher.find();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment