validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Can we have a containsEmail() and containsURL()?

Open U-4-E-A opened this issue 2 years ago • 6 comments

Use case - you don't want passwords to contain emails or websites (too guessable). Would like to interrogate the string to see if it contains than that just is. Thanks.

U-4-E-A avatar Nov 27 '21 22:11 U-4-E-A

You can easily use:

validator.isEmail('[email protected]') || validator.isUrl('https://google.com')

before doing anything with the password.

heanzyzabala avatar Dec 12 '21 07:12 heanzyzabala

You can easily use:

validator.isEmail('[email protected]') || validator.isUrl('https://google.com')

before doing anything with the password.

This checks if the string is an email or url, rather than checking to see if the string contains an email or url.

import isEmail from 'validator/lib/isEmail'

isEmail('[email protected]') // true
isEmail(':::[email protected]:::') // false

U-4-E-A avatar Dec 12 '21 11:12 U-4-E-A

@U-4-E-A I got an idea can u assign me to this issue?

Chetan-B-B avatar Jan 27 '22 14:01 Chetan-B-B

@Chetan-B-B there are already two PRs for this, maybe you could review those and see if your idea aligns?

WikiRik avatar Jan 27 '22 14:01 WikiRik

For those it may help, I was planning on using this for testing for emails/urls in passwords. This can be done using user input with zxcvbn-ts, which also provides l33t matching functionality.

U-4-E-A avatar Jul 01 '22 10:07 U-4-E-A

I'm not sure how I feel about this . AFAIR this kind of stuff has been discussed in the past and we decided not to add more functionalities to the package, especially such features that can be implemented by the end-user (customized through the existing validator method). To me, this doesn't sound like a necessary addition, given that it's non-blocking & not very complex to implement on your own :) You can see the input from @profnandaa here https://github.com/validatorjs/validator.js/pull/1886#issuecomment-1105951094

rubiin avatar Jul 28 '22 17:07 rubiin

ok, seeing as those PRs have been shut down, I don't think there is any sense in having the issue still open. thanks for your report, but closing it as "WONTDO", as outlined here https://github.com/validatorjs/validator.js/pull/1886#issuecomment-1105951094

pano9000 avatar Jan 23 '23 23:01 pano9000