java2db

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 :  abcde@xyz.com or Abcd@xyz.com).
(?!.*\\s) To check blank spaces.
.{4,15} Length should be 4 min and 15 max (ie abcde@xyz.com).
[a-z]{4,10} Small alphabets with 4 min and 10 max length (ie abcd@xyz.com).
[.]  . character (ie abcd@xyz.com)
[a-z]{2,5} Small alphabets with 2 min and 5 max length (ie abcd@xyz.com).

Sample regular expression to validate email address :

^[a-zA-Z](?!.*\\s).{4,15}@([a-z]{4,10})[.][a-z]{2,5}

 

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]



^ <