I have a form and among the fields to fill is the mail I want to make a control so that the input address is consistent with the standard mails
responsableTechnique.setMail(mailResponsable.getText());
I have a form and among the fields to fill is the mail I want to make a control so that the input address is consistent with the standard mails
responsableTechnique.setMail(mailResponsable.getText());
You can with regex, example :
public static void main(String[]args){
String regex = "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)+$";
Pattern.matches(regex,"test@test.fr"); //True
Pattern.matches(regex,"test.test@test.fr"); //True
Pattern.matches(regex,"testtest.fr"); //False
Pattern.matches(regex,"test.test@testfr"); //False
Pattern.matches(regex,"test@test."); //False
Pattern.matches(regex,"test@te@st.fr"); //False
}
So for your example :
String regex = "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)+$";
String mail = mailResponsable.getText();
if(Pattern.matches(regex,mail)) responsableTechnique.setMail(mail);