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

Published: 15 August 2013
on channel: 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


On this page of the site you can watch the video online How to validate 'email' using Regular Expression in Java with NetBeansIDE with a duration of hours minute second in good quality, which was uploaded by the user raksrahul 15 August 2013, share the link with friends and acquaintances, this video has already been watched 18,353 times on youtube and it was liked by 50 viewers. Enjoy your viewing!