PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/app/src/main/java/com/syncmed/doc360_doctor_android/helpers/Utility.java

https://bitbucket.org/syncmed/doc360-doctor-android
Java | 68 lines | 51 code | 14 blank | 3 comment | 8 complexity | eb5301e81ad9634b7083e2a9ae7789cc MD5 | raw file
  1. package com.syncmed.doc360_doctor_android.helpers;
  2. import android.text.TextUtils;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9. /**
  10. * Created by ernestgayyed on 10/08/2017.
  11. */
  12. public class Utility {
  13. private static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  14. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  15. private static final Pattern LETTERS_ONLY =
  16. Pattern.compile("[a-zA-Z]+", Pattern.CASE_INSENSITIVE);
  17. public static boolean isEmailValid(String email) {
  18. if (TextUtils.isEmpty(email)) {
  19. return false;
  20. } else {
  21. Matcher emailMatcher = VALID_EMAIL_ADDRESS_REGEX.matcher(email);
  22. return emailMatcher.find();
  23. }
  24. }
  25. public static boolean isDateValid(String date) {
  26. SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
  27. df.setLenient(false);
  28. boolean valid = false;
  29. try {
  30. df.parse(date);
  31. return true;
  32. } catch (ParseException e) {
  33. } // valid will still be false
  34. return true;
  35. }
  36. public static boolean isStringOnly(String text) {
  37. return text.matches("[a-zA-Z]+");
  38. }
  39. public static boolean isStringEmptyOrNull(String text) {
  40. if (text == null || text == "" || text.equals("")) {
  41. return true;
  42. }
  43. return false;
  44. }
  45. public static boolean isNumbersOnly(String text) {
  46. return text.matches("[0-9]+");
  47. }
  48. public static boolean isPasswordValid(String password) {
  49. if (password.length() > 6) {
  50. return true;
  51. }
  52. return false;
  53. }
  54. }