PageRenderTime 206ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/cyclingeventapplication/src/main/java/cs472/mum/service/SignUpService.java

https://bitbucket.org/danhuycao/cs472_mum
Java | 40 lines | 27 code | 11 blank | 2 comment | 4 complexity | 436f9128ce6a05a304f47280f5785b6c MD5 | raw file
  1. //// Didi
  2. package cs472.mum.service;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Locale;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8. //Didi
  9. public class SignUpService {
  10. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  11. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  12. public List<String> validateSignUpForm(String firstName, String lastName, String email,String password) {
  13. List<String> result = new ArrayList<String>();
  14. if (firstName.isEmpty()) {
  15. result.add("First name required");
  16. }
  17. if (lastName.isEmpty()) {
  18. result.add("Last name required");
  19. }
  20. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(email);
  21. if (email.isEmpty()|| !matcher.find()) {
  22. result.add("E-mail required");
  23. }
  24. if (password.isEmpty() ) {
  25. result.add("Last name required. (password must be more than 6 characters)");
  26. }
  27. return result;
  28. }
  29. }