Guest User

Untitled

a guest
Nov 14th, 2018
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. public void checkValid() {
  2. List<String> emails = new ArrayList();
  3. //Valid Email Ids
  4. emails.add("simple@example.com");
  5. emails.add("very.common@example.com");
  6. emails.add("disposable.style.email.with+symbol@example.com");
  7. emails.add("other.email-with-hyphen@example.com");
  8. emails.add("fully-qualified-domain@example.com");
  9. emails.add("user.name+tag+sorting@example.com");
  10. emails.add("fully-qualified-domain@example.com");
  11. emails.add("x@example.com");
  12. emails.add("carlosd'intino@arnet.com.ar");
  13. emails.add("example-indeed@strange-example.com");
  14. emails.add("admin@mailserver1");
  15. emails.add("example@s.example");
  16. emails.add("" "@example.org");
  17. emails.add(""john..doe"@example.org");
  18.  
  19. //Invalid emails Ids
  20. emails.add("Abc.example.com");
  21. emails.add("A@b@c@example.com");
  22. emails.add("a"b(c)d,e:f;g<h>i[j\k]l@example.com");
  23. emails.add("just"not"right@example.com");
  24. emails.add("this is"not\allowed@example.com");
  25. emails.add("this\ still"not\allowed@example.com");
  26. emails.add("1234567890123456789012345678901234567890123456789012345678901234+x@example.com");
  27. emails.add("john..doe@example.com");
  28. emails.add("john.doe@example..com");
  29.  
  30. String regex = "^[a-zA-Z0-9_!#$%&'*+/=? \"`{|}~^.-]+@[a-zA-Z0-9.-]+$";
  31.  
  32. Pattern pattern = Pattern.compile(regex);
  33. int i=0;
  34. for(String email : emails){
  35. Matcher matcher = pattern.matcher(email);
  36. System.out.println(++i +"."+email +" : "+ matcher.matches());
  37. }
  38. }
  39.  
  40. 1.simple@example.com : true
  41. 2.very.common@example.com : true
  42. 3.disposable.style.email.with+symbol@example.com : true
  43. 4.other.email-with-hyphen@example.com : true
  44. 5.fully-qualified-domain@example.com : true
  45. 6.user.name+tag+sorting@example.com : true
  46. 7.fully-qualified-domain@example.com : true
  47. 8.x@example.com : true
  48. 9.carlosd'intino@arnet.com.ar : true
  49. 10.example-indeed@strange-example.com : true
  50. 11.admin@mailserver1 : true
  51. 12.example@s.example : true
  52. 13." "@example.org : true
  53. 14."john..doe"@example.org : true
  54. 15.Abc.example.com : false
  55. 16.A@b@c@example.com : false
  56. 17.a"b(c)d,e:f;g<h>i[jk]l@example.com : false
  57. 18.just"not"right@example.com : true
  58. 19.this is"notallowed@example.com : false
  59. 20.this still"notallowed@example.com : false
  60. 21.1234567890123456789012345678901234567890123456789012345678901234+x@example.com : true
  61. 22.john..doe@example.com : true
  62. 23.john.doe@example..com : true
  63.  
  64. 1.simple@example.com : true
  65. 2.very.common@example.com : true
  66. 3.disposable.style.email.with+symbol@example.com : true
  67. 4.other.email-with-hyphen@example.com : true
  68. 5.fully-qualified-domain@example.com : true
  69. 6.user.name+tag+sorting@example.com : true
  70. 7.fully-qualified-domain@example.com : true
  71. 8.x@example.com : true
  72. 9.carlosd'intino@arnet.com.ar : true
  73. 10.example-indeed@strange-example.com : true
  74. 11.admin@mailserver1 : true
  75. 12.example@s.example : true
  76. 13." "@example.org : true
  77. 14."john..doe"@example.org : true
  78. 15.Abc.example.com : false
  79. 16.A@b@c@example.com : false
  80. 17.a"b(c)d,e:f;g<h>i[jk]l@example.com : false
  81. 18.just"not"right@example.com : false
  82. 19.this is"notallowed@example.com : false
  83. 20.this still"notallowed@example.com : false
  84. 21.1234567890123456789012345678901234567890123456789012345678901234+x@example.com : false
  85. 22.john..doe@example.com : false
  86. 23.john.doe@example..com : false
  87.  
  88. 1234567890123456789012345678901234567890123456789012345678901234+x@example.com
  89. john..doe@example.com
  90. john.doe@example..com
  91. just"not"right@example.com
Add Comment
Please, Sign In to add comment