I must validate two types of expressions for an email:
letter.letter.year greater than 2018@uts.edu.co
j.g.2019@uts.edu.co
0-2018.letter.letter@*.com.co
0.j.g@cloudmail.com.co
I have used these two regex expressions but they have not worked:
[a-zA-Z] + [.]? [a-zA-Z] + [.]? [2-9] [0-9] (?! 18 $) [1-9] [1-9] ? + $ \ @ uts ([.]) edu ([.]) co
\ b ([0] | 20 [0-1] [0-8] | 2019) \ b + [.]? [a-zA-Z] + [.]? [a-zA-Z] + \ @ [ a-zA-Z] ([.]) com ([.]) co
private void btn_validarActionPerformed(java.awt.event.ActionEvent evt) {
String w_correo = caja_correo.getText();
Pattern p_correo1 = Pattern.compile("^[a-zA-Z]+[.]?[a-zA-Z]+[ .]?[2-9][0-9](?!18$)[1-9][1-9]?+$\\@uts([.])edu([\\.])co$");
Matcher m_correo1 = p_correo1.matcher(w_correo);
Pattern p_correo2 = Pattern.compile("^\\b([0]|20[0-1][0-8]|2019)\\b+[.]?[a-zA-Z]+[.]?[a-zA-Z]+\\@ [a-zA-Z] ([.])com([\\.])co$");
Matcher m_correo2 = p_correo2.matcher(w_correo);
if (m_correo1.matches()) {
String validacion = "";
validacion = validacion + "Direccion de correo electrónico correcta<br/>";
correcto.setForeground(Color.GREEN);
}
else {
String validacion = "";
if (!m_correo1.matches()) {
validacion= validacion + "Direccion de correo electrónico incorrecta<br/>";
incorrecto.setBackground(Color.RED);
}
}
if (m_correo2.matches()) {
String validacion = "";
validacion = validacion + "Direccion de correo electrónico correcta<br/>";
correcto.setForeground(Color.GREEN);
}
else {String validacion = "";
if (!m_correo2.matches()) {
validacion= validacion + "Direccion de correo electrónico incorrecta<br/>";
incorrecto.setBackground(Color.RED);
}
}
}
When you tried to validate a valid email the result is that the email is incorrect. the button NO is shown red, but the button SI is not shown green.