user interface - GUI Email validator in Java -
i'm working on gui validation... please see problem below...
how validate email specific format? @ least 1 digit before @ , 1 digit after , @ least 2 letters after dot.
string emailformat = "m@m.co"; pattern patternemail = pattern.compile("\\d{1,}@\\d{1,}.\\d{2,}"); matcher matchername = patternemail.matcher(studentemail);
this regex pattern emails
string pt = "^[_a-za-z0-9-\\+]+(\\.[_a-za-z0-9-]+)*@[a-za-z0-9-]+(\\.[a-za-z0-9]+)*(\\.[a-za-z]{2,})$";
you can try this
list email = arrays.aslist("xyzl@gmail.com", "@", "sxd"); predicate<string> validmail = (n) -> n.matches(pt); email.stream().filter(validmail).foreach((n) -> system.out.println(n));
this description can change according need.
^ #start of line [_a-za-z0-9-\\+]+ # must start string in bracket [ ], must contains 1 or more (+) ( # start of group #1 \\.[_a-za-z0-9-]+ # follow dot "." , string in bracket [ ], must contains 1 or more (+) )* # end of group #1, group optional (*) @ # must contains "@" symbol [a-za-z0-9-]+ # follow string in bracket [ ], must contains 1 or more (+) ( # start of group #2 - first level tld checking \\.[a-za-z0-9]+ # follow dot "." , string in bracket [ ], must contains 1 or more (+) )* # end of group #2, group optional (*) ( # start of group #3 - second level tld checking \\.[a-za-z]{2,} # follow dot "." , string in bracket [ ], minimum length of 2 ) # end of group #3 $ #end of line
Comments
Post a Comment