Validate an email address

PHOTO EMBED

Tue Aug 09 2022 19:30:49 GMT+0000 (Coordinated Universal Time)

Saved by @johnnye562 #javascript

const emailIsValid = (email) => {
  if (!(typeof email === "string" || email instanceof String)) {
    console.error(`string expected, ${typeof email} provided`)
    return false
  }
  const expression = /\S+@\S+\.\S+/
  return expression.test(email)
}

emailIsValid("somebody@somewhere.com") // true
emailIsValid("nobody@nowhere") // false
content_copyCOPY

https://justacoding.blog/9-useful-javascript-utility-functions/