Code for validating email in java
There may be more usecase but that’s not point of discussion here. validating email address in java using regular expressions.
In the last post, I explained about java regular expression in detail with some examples. If we want to restrict user to enter only specific top level domains like , .Only email id containing (com , org )tld are valid .The following conditions may be applied for validating email. Alphanumeric Characters ( i.e Uppercase letters (A-Z) , Lowercase Letters ( a–z), Digits (0-9) ) 2. in ,org, com) The following Pattern may be used for validating the E-Mail Address. \w is predefined character class for a word character: [a-z A-Z_0-9] 1. \.)) -If the next character is a dot (.), matches it. //For Better understanding of the above Pattern , we can split into various parts in order. [\w] -The first character of the Email matches any alphabetic character from a to z or A to Z or any numeric character from 0 to 9. If it is not a dot, looks for next character and continue the match. \.) ensures, there should not be two or more dot (.) consecutively 3.