How to validate email address by using regular expression in java

Regular Expression is very useful to apply validation for various input fields like email address, password . To validate email address using regular expression , use the below conditions.


Conditions to validate email address :

Beginning of the regex.
[a-zA-Z] Small or capital alphabet.(Ex : or
(?!.*\\s) To check blank spaces.
.{4,15} Length should be 4 min and 15 max (ie
[a-z]{4,10} Small alphabets with 4 min and 10 max length (ie
[.]  . character (ie
[a-z]{2,5} Small alphabets with 2 min and 5 max length (ie

Sample regular expression to validate email address :



Example code to validate email address:

Execution Result:

validate email address The String index starts from zero(0).
validate email address Change {}  values , to set maximum and minimum lengths.

Related Posts :
How to validate the password by using regular expression in java
   [will not be published]

^ <