PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/dc/musicmaster/DataValidation.java

https://bitbucket.org/dccor/musicmasterweb
Java | 33 lines | 16 code | 6 blank | 11 comment | 0 complexity | ceb4c3816ef20ce46eaf28b3e97218f4 MD5 | raw file
  1. package com.dc.musicmaster;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4. /**
  5. * this Class validates the Email input
  6. * @author D.Kos
  7. *
  8. */
  9. public class DataValidation {
  10. @SuppressWarnings("unused")
  11. private Pattern pattern;
  12. @SuppressWarnings("unused")
  13. private Matcher matcher;
  14. /** the Pattern with Email Regular Expression */
  15. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  16. Pattern.compile("^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
  17. , Pattern.CASE_INSENSITIVE);
  18. /**
  19. * Validates User Email with RegularExpressions
  20. * @param emailStr
  21. * @return true (ONLY if Matches Pattern)
  22. */
  23. public static boolean validateEmail(String emailStr) {
  24. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr);
  25. return matcher.find();
  26. }
  27. }