Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void checkValid() {
- List<String> emails = new ArrayList();
- //Valid Email Ids
- emails.add("simple@example.com");
- emails.add("very.common@example.com");
- emails.add("disposable.style.email.with+symbol@example.com");
- emails.add("other.email-with-hyphen@example.com");
- emails.add("fully-qualified-domain@example.com");
- emails.add("user.name+tag+sorting@example.com");
- emails.add("fully-qualified-domain@example.com");
- emails.add("x@example.com");
- emails.add("carlosd'intino@arnet.com.ar");
- emails.add("example-indeed@strange-example.com");
- emails.add("admin@mailserver1");
- emails.add("example@s.example");
- emails.add("" "@example.org");
- emails.add(""john..doe"@example.org");
- //Invalid emails Ids
- emails.add("Abc.example.com");
- emails.add("A@b@c@example.com");
- emails.add("a"b(c)d,e:f;g<h>i[j\k]l@example.com");
- emails.add("just"not"right@example.com");
- emails.add("this is"not\allowed@example.com");
- emails.add("this\ still"not\allowed@example.com");
- emails.add("1234567890123456789012345678901234567890123456789012345678901234+x@example.com");
- emails.add("john..doe@example.com");
- emails.add("john.doe@example..com");
- String regex = "^[a-zA-Z0-9_!#$%&'*+/=? \"`{|}~^.-]+@[a-zA-Z0-9.-]+$";
- Pattern pattern = Pattern.compile(regex);
- int i=0;
- for(String email : emails){
- Matcher matcher = pattern.matcher(email);
- System.out.println(++i +"."+email +" : "+ matcher.matches());
- }
- }
- 1.simple@example.com : true
- 2.very.common@example.com : true
- 3.disposable.style.email.with+symbol@example.com : true
- 4.other.email-with-hyphen@example.com : true
- 5.fully-qualified-domain@example.com : true
- 6.user.name+tag+sorting@example.com : true
- 7.fully-qualified-domain@example.com : true
- 8.x@example.com : true
- 9.carlosd'intino@arnet.com.ar : true
- 10.example-indeed@strange-example.com : true
- 11.admin@mailserver1 : true
- 12.example@s.example : true
- 13." "@example.org : true
- 14."john..doe"@example.org : true
- 15.Abc.example.com : false
- 16.A@b@c@example.com : false
- 17.a"b(c)d,e:f;g<h>i[jk]l@example.com : false
- 18.just"not"right@example.com : true
- 19.this is"notallowed@example.com : false
- 20.this still"notallowed@example.com : false
- 21.1234567890123456789012345678901234567890123456789012345678901234+x@example.com : true
- 22.john..doe@example.com : true
- 23.john.doe@example..com : true
- 1.simple@example.com : true
- 2.very.common@example.com : true
- 3.disposable.style.email.with+symbol@example.com : true
- 4.other.email-with-hyphen@example.com : true
- 5.fully-qualified-domain@example.com : true
- 6.user.name+tag+sorting@example.com : true
- 7.fully-qualified-domain@example.com : true
- 8.x@example.com : true
- 9.carlosd'intino@arnet.com.ar : true
- 10.example-indeed@strange-example.com : true
- 11.admin@mailserver1 : true
- 12.example@s.example : true
- 13." "@example.org : true
- 14."john..doe"@example.org : true
- 15.Abc.example.com : false
- 16.A@b@c@example.com : false
- 17.a"b(c)d,e:f;g<h>i[jk]l@example.com : false
- 18.just"not"right@example.com : false
- 19.this is"notallowed@example.com : false
- 20.this still"notallowed@example.com : false
- 21.1234567890123456789012345678901234567890123456789012345678901234+x@example.com : false
- 22.john..doe@example.com : false
- 23.john.doe@example..com : false
- 1234567890123456789012345678901234567890123456789012345678901234+x@example.com
- john..doe@example.com
- john.doe@example..com
- just"not"right@example.com
Add Comment
Please, Sign In to add comment