You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Zulfi Khan <zu...@yahoo.com.INVALID> on 2024/01/16 05:22:34 UTC
Apache email validator: import and usage problem
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 testingemail 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
importorg.apache.commons.validator.routines.InetAddressValidator;
https://github.com/apache/commons-validator/blob/master/src/main/java/org/apache/commons/validator/EmailValidator.java
packagecom.mycompany.validatename;
//importorg.apache.commons.validator.*; ERROR, How to correct?
//importorg.apache.commons.validator.routines.InetAddressValidator; ERROR,how to coorect?
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
importjavax.swing.JOptionPane;
public classValidateNameForm extends javax.swing.JFrame {
publicValidateNameForm() {
initComponents();
}
private voidjTF1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO addyour handling code here:
}
private voidCheckIfInputValid(String input, String regex){
String s;
Patternpattern = Pattern.compile(regex);
s =input.trim();
Matchermatcher = pattern.matcher(s);
JOptionPane.showMessageDialog(null, "Input "+s+" isvalid " +
String.valueOf(matcher.matches()));
}
private voidjButton1ActionPerformed(java.awt.event.ActionEvent evt) {
StringemailAddress= jTF1.getText();
booleanisValidEmail =EmailValidator.getInstance().isValid(emailAddress);//SYNTAX ERROR
}
public staticvoid 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) {
:
:
}
// Variablesdeclaration - do not modify
privatejavax.swing.JButton jButton1;
privatejavax.swing.JLabel jLabel1;
privatejavax.swing.JTextField jTF1;
// End ofvariables declaration
}
Please guide me whatis the correct import statement for email validator ? I have show twowrong import statements, please tell me the correct ones.
What is the correctsyntax of :
boolean isValidEmail= EmailValidator.getInstance().isValid(emailAddress);
Somebody, pleaseguide me.
Zulfi.
Re: Apache email validator: import and usage problem
Posted by Pieter van den Hombergh <pi...@gmail.com>.
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 <zu...@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.
>
>
>
>
>