You might want to add the required dependency. If you are working with maven (recommended) then here is a minimal pom that will work finding the jar from maven central.
---- <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>m</groupId> <artifactId>emailvalidator</artifactId> <version>0.1</version> <packaging>jar</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <exec.mainClass>m.emailvalidator.Emailvalidator</exec.mainClass> <maven.compiler.release>21</maven.compiler.release> </properties> <dependencies> <!-- required dependency below --> <dependency> <groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> <version>1.8.0</version> <type>jar</type> </dependency> </dependencies> </project> ---- also find a minmal project example attached. Met vriendelijke groet, Pieter van den Hombergh. Kerboschstraat 12 5913 WH Venlo On Tue, Jan 16, 2024 at 6:23 AM Zulfi Khan <zulfi6...@yahoo.com.invalid> wrote: > Hi, > > I am trying to use the Apache email validator code. > > I tried to use two import statements to import the apache email validator > for testing email addresses but they are not working: > > > import org.apache.commons.validator.routines.EmailValidator; > > > https://stackoverflow.com/questions/624581/what-is-the-best-java-email-address-validation-method > > and > > import org.apache.commons.validator.routines.InetAddressValidator; > > > https://github.com/apache/commons-validator/blob/master/src/main/java/org/apache/commons/validator/EmailValidator.java > > > > package com.mycompany.validatename; > > //import org.apache.commons.validator.*; ERROR, How to correct? > > //import org.apache.commons.validator.routines.InetAddressValidator; > ERROR, how to coorect? > > import java.util.regex.Matcher; > > import java.util.regex.Pattern; > > import javax.swing.JOptionPane; > > > public class ValidateNameForm extends javax.swing.JFrame { > > > public ValidateNameForm() { > > initComponents(); > > } > > private void jTF1ActionPerformed(java.awt.event.ActionEvent evt) { > > // TODO add your handling code here: > > } > > private void CheckIfInputValid(String input, String regex){ > > String s; > > Pattern pattern = Pattern.compile(regex); > > s = input.trim(); > > Matcher matcher = pattern.matcher(s); > > JOptionPane.showMessageDialog(null, "Input "+s+" is valid " + > > String.valueOf(matcher.matches())); > > } > > private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { > > String emailAddress= jTF1.getText(); > > boolean isValidEmail = > EmailValidator.getInstance().isValid(emailAddress);//SYNTAX ERROR > > } > > > public static void main(String args[]) { > > try { > > for (javax.swing.UIManager.LookAndFeelInfo info : > > javax.swing.UIManager.getInstalledLookAndFeels()) { > > if ("Nimbus".equals(info.getName())) { > > javax.swing.UIManager.setLookAndFeel(info.getClassName()); > > break; > > } > > } > > } catch (ClassNotFoundException ex) { > > : > > : > > } > > > // Variables declaration - do not modify > > private javax.swing.JButton jButton1; > > private javax.swing.JLabel jLabel1; > > private javax.swing.JTextField jTF1; > > // End of variables declaration > > } > > > Please guide me what is the correct import statement for email validator ? > I have show two wrong import statements, please tell me the correct ones. > > > What is the correct syntax of : > > > boolean isValidEmail = EmailValidator.getInstance().isValid(emailAddress); > > > Somebody, please guide me. > > > Zulfi. > > > > >
<<attachment: emailvalidator.zip>>
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org For additional commands, e-mail: users-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists