Sunday, May 30, 2010

java regex to validate email

/**
*@author Sunny Jain
*@Email i_look_like_sunny@hotmail.com
*@version 1.0
*@since 02-March-2010
*@about - this Class will use regular express to validate the email address.
*\\p{Alpha} means - any alphabet ( case insensitive)
*\\p{Alnum} means - any alphabet + any digit ( case insensitive)
*It checks any email address that ends with .com, .org, and co.(any country)
*/

public class Main {

public static void main(String... args){
String alpha = "i_look_like_sunny@hotmail.co.in";
String ALPHAREGEX = "[\\p{Alpha}]+[\\p{Alnum}_.]*[@][\\p{Alnum}]+[.]" +
"(([cC][oO][mM])|([oO][rR][gG])|([cC][oO][.][\\p{Alpha}]*))";

System.out.println(ALPHAREGEX);
System.out.println(alpha.matches(ALPHAREGEX));
}
}

1 comment:

ganesh said...


Hi there, awesome site. I thought the topics you posted on were very interesting. I tried to add your RSS to my feed reader and it a few. take a look at it,

hopefully I can add you and follow.


Java Training Courses