Validating email in java updating a split level home


Hi I'm a newbie about the using of regular expression I have this regular expression to validate an mail but I don't understand the meaning. mail Pattern = Pattern.compile("[a-z A-Z_0-9]*[.[a-z A-Z_0-9]*]*@[a-z A-Z_0-9]*[.[a-z A-Z_0-9]*]*.[a-z A-Z]");answer 1 If you're using Java, a much simpler option is to use Java Mail's Internet Address class to validate the address for you: public boolean is Email Valid(String email) This will perform validation based upon RFC822.

validating email in java-69

This is the reason that Apache commons Email Validator uses several regular expressions and some additional logic written in java.^ #start of the line [_A-Za-z0-9-\\ ] # must start with string in the bracket [ ], must contains one or more ( ) ( # start of group #1 \\.[_A-Za-z0-9-] # follow by a dot "." and string in the bracket [ ], must contains one or more ( ) )* # end of group #1, this group is optional (*) @ # must contains a "@" symbol [A-Za-z0-9-] # follow by string in the bracket [ ], must contains one or more ( ) ( # start of group #2 - first level TLD checking \\.[A-Za-z0-9] # follow by a dot "." and string in the bracket [ ], must contains one or more ( ) )* # end of group #2, this group is optional (*) ( # start of group #3 - second level TLD checking \\.[A-Za-z] # follow by a dot "." and string in the bracket [ ], with minimum length of 2 ) # end of group #3 $ #end of the line The combination means, email address must start with “_A-Za-z0-9-\\ ” , optional follow by “.[_A-Za-z0-9-]”, and end with a “@” symbol.

[email protected]%*– email’s tld is only allow character and digit 9.

Restrictions in above regex are:1) A-Z characters allowed 2) a-z characters allowed 3) 0-9 numbers allowed 4) Additionally email may contain only dot(.), dash(-) and underscore(_) 5) Rest all characters are not allowed Let’s test some email addresses against above regex.

Possible Duplicate: What is the best regular expression for validating email addresses?

List emails = new Array List(); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); //Invalid emails emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); String regex = "^[\w!