Tuesday, June 21, 2016

Regular Expression in Java for Email Validation

class RegexTest {
   public static void main(String[] args) {

      String my_regex = "^[a-z0-9._]+@[a-z0-9.-]+\\.[a-z]{2,3}$";
     
      String my_email = "tekendra587@gmail.com";
      Boolean b = my_email.matches(my_regex);
      System.out.println("Email address "+my_email+" is: " + b);
     
      String my_another_email = "user^domain.co.in";
      b = my_another_email.matches(my_regex);
      System.out.println("Email address "+my_another_email+" is: " + b);
   }
}

No comments:

Post a Comment