Email Regex Function doesn't work in React for Validation

Niklas

I am using the following React Function for email Regex, but it doesn't work.

When i try this email-address: [email protected] i get the the error: "Email is invalid"

Here is my FormValidation Function to check the values:

import { emailRegex } from "./regex";

export function validateEmail(email) {
  if (!email.length) {
    return {
      status: true,
      value: "Email is required"
    };
  } else if (!emailRegex.test(email)) {
    console.log(email);
    return {
      status: true,
      value: "Email is invalid"
    };
  }
  return {
    status: false,
    value: ""
  };
}

export function validatePassword(password) {
  if (!password.length) {
    return {
      status: true,
      value: "Password is required"
    };
  } else if (password.length <= 6) {
    return {
      status: true,
      value: "Password is invalid"
    };
  }
  return {
    status: false,
    value: ""
  };
}

and here is my emailRegex Function:

export const emailRegex = /^(([^<>()[]\\.,;:\s@\"]+(\.[^<>()[]\\.,;:\s@\"]+)*)|(\".+\"))@(([[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

Where is the issue of that? Thanks for our help

Alfred Ayi-bonte

export const emailRegex=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related