1

I am trying to validate email input with validator.js. This works, but there is a case that it doesn't validate properly.

[email protected]

I would like to sort this kind of addresses as not valid. I have already tried to use domain_specific_validation: true, but this didn't work.

Is there any solution for this problem?

P.S. I don't want to use a regular expression.

2
  • I don't want to use regExp...Are you sure the plugin you are using is not using any? Commented Oct 8, 2018 at 11:21
  • I know that this package uses regExp , i just want to validate email with this package , not to write regExp. Commented Oct 8, 2018 at 11:23

1 Answer 1

1

According to validator.js codebase, it only checks if top level domain (tld) matches the specific regexp. And as tld list can always be extended via new registered items, this seems to be correct solution. So, commmmmmm is something that might be a tld, and that's why validation returns true.

Other solution might be to check if tld is in registered tld list, you can use tld-list npm package for that:

const tldList = require('tld-list');
tldList.includes('[email protected]'.split('.').pop());

But this solution requires constantly update this package, to be able to track new tld's as well.

There is also a validate-tld package which does request to the registration service to check if tld is valid:

var validateTld = require("validate-tld")
new validateTld().validate('commmm').then( console.log )

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you a lot . Now its clear to me the problem and solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.