Friday, 8 May 2015

Selenium:Validations for mail

package regularexpressions;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Mailid {
public static void main(String[] args) {
    String mid="scjpramesh@gmail.com";
    //String target="^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
   
    String target="^[_A-Za-z0-9-]+@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
   
    Pattern p =Pattern.compile(target);
    Matcher m=p.matcher(mid);
    if(m.find()&&m.group().equals(mid)){
        System.out.println("valid mail id");
    }
    else
    {
        System.out.println("invalid mail id");
    }
}
}

No comments:

Post a Comment