How to validate 'email' using Regular Expression in Java with NetBeansIDE
1. Open NetBeansIDE
2. In your project Make a java form(e.g. JFrame Form)
2.1 Design this Form with one JTextField and a button in it.
3. Make Validate.java class
3.1 In this class make a static method with code:
public static boolean validateEmail(String email) {
boolean status=false;
String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
"[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher=pattern.matcher(email);
if(matcher.matches())
{
status=true;
}
else{
status=false;
}
return status;
}
4. Right Click on Button and Goto Events~Action~actionPerformed
4.1 In this method Call the 'validateEmail' method of Validate class
as:
boolean status=Validate.validateEmail(jTextField1.getText());
if(status){
jLabel2.setText("Email Valid");
}else{
jLabel2.setText("Not Valid Email");
}
5. Run your project with JForm.
6. Check the Validation.
7. Finish
Thank You :)
Follow us on :
Facebook : / raksrahul-100219708647780
Instagram : / raksrahul_ig
#java #NetBeansIDE #programming #coding
Sur cette page du site, vous pouvez voir la vidéo en ligne How to validate 'email' using Regular Expression in Java with NetBeansIDE durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur raksrahul 15 août 2013, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 18,353 fois et il a aimé 50 téléspectateurs. Bon visionnage!