Suppose my email address is [email protected]
and I want to check if yahoo.com
is a valid domain or not.
Can anyone tell me which Java API I can use for this?
You can use org.apache.commons.validator.routines.DomainValidator.
First add maven dependency
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
then:
boolean isValid = DomainValidator.getInstance().isValid("yahoo.com");
One thing that you could do is trying to resolve "yahoo.com". Something like this:
public static void main(String[] args) throws UnknownHostException {
InetAddress inetAddress = InetAddress.getByName("yahoo.com");
System.out.println(inetAddress.getHostName());
System.out.println(inetAddress.getHostAddress());
}
which outputs:
yahoo.com
67.195.160.76
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With