File tree Expand file tree Collapse file tree
src/test/java/api/org/apache/commons/validator Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 </properties >
2626
2727 <dependencies >
28+ <dependency >
29+ <groupId >commons-validator</groupId >
30+ <artifactId >commons-validator</artifactId >
31+ <version >1.7</version > <!-- Use the latest version available -->
32+ </dependency >
2833 <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
2934 <dependency >
3035 <groupId >commons-lang</groupId >
Original file line number Diff line number Diff line change 1+ package api .org .apache .commons .validator ;
2+
3+ import org .apache .commons .validator .routines .EmailValidator ;
4+
5+ public class EmailValidatorExample {
6+
7+ public static void main (String [] args ) {
8+ String email = "example@example.com" ;
9+ String emailWrong = "exampleexample.com" ;
10+
11+ if (isValidEmail (email )) {
12+ System .out .printf ("Valid email address:%s!%n" ,email );
13+ } else {
14+ System .out .printf ("Invalid email address;%s!%n" , email );
15+ }
16+
17+ if (isValidEmail (emailWrong )) {
18+ System .out .printf ("Valid email address:%s!%n" ,emailWrong );
19+ } else {
20+ System .out .printf ("Invalid email address;%s!%n" , emailWrong );
21+ }
22+ }
23+
24+ private static boolean isValidEmail (String email ) {
25+ // Create an instance of EmailValidator
26+ EmailValidator validator = EmailValidator .getInstance ();
27+
28+ // Check if the email is valid
29+ return validator .isValid (email );
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments