mfbx9da4 / deep-email-validator

Validates regex, typos, disposable, dns and smtp
MIT License
873 stars 92 forks source link

Error while hooking it with yup in React #23

Closed arabhiar closed 3 years ago

arabhiar commented 3 years ago

Hi, I am getting an error

deep_email_validatorWEBPACK_IMPORTED_MODULE6default.a.validate is not a function

while trying to hook deep-email-validator with React.

import emailValidator from 'deep-email-validator';

const isEmailValid = async (email) => {
  return emailValidator.validate(email);
};

const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/i;
const passwordRegex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/g;
// const phoneRegex = /^([0]{1}|\+?[234]{3})([7-9]{1})([0|1]{1})([\d]{1})([\d]{7})$/g
const validationSchema = yup.object().shape({
  email: yup
    .string()
    .matches(emailRegex, 'Invalid email.')
    .test('working-email', 'Must be an working email', async (value) => {
      const res = await isEmailValid(value);
      return res.valid;
    })
    .required('Email is required.'),
  password: yup
    .string()
    .required('Password is required.')
    .matches(
      passwordRegex,
      'Password must be min 8 characters, have 1 special character[#?!@$%^&*-], 1 uppercase, 1 lowercase and 1 number.'
    ),
  confirmPassword: yup
    .string()
    .test('password-match', 'Passwords must match.', function (value) {
      return this.parent.password === value;
    }),
`});

Please look into it @mfbx9da4

mfbx9da4 commented 3 years ago

This is not compatible with the browser

arabhiar commented 3 years ago

Okay, then I can only use this package with the node app.