How to validate 'email' using Regular Expression in Java with NetBeansIDE

Опубликовано: 29 Март 2026
на канале: raksrahul
18,353
50

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