Giter Club home page Giter Club logo

Comments (3)

zaggino avatar zaggino commented on September 14, 2024 1

You can do in your project:

const validator = require('validator'); // already imported by z-schema so you don't need it as dependency in package.json
ZSchema.registerFormat(
    "email",
    function (email) {
        if (typeof email !== "string") {
            return true;
        }
        return validator.isEmail(email, { "require_tld": true, "allow_utf8_local_part": false });
    }
);

I wouldn't modify the default behaviour unless we need to match the official test suite (maybe open a PR there?): https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/master/tests/draft4/format.json

from z-schema.

shane-tomlinson avatar shane-tomlinson commented on September 14, 2024

Looking at the IETF spec about internationalized email addresses, email addresses are allowed to contain utf-8 characters:

An SMTP server that announces the SMTPUTF8 extension MUST be prepared
to accept a UTF-8 string [RFC3629] in any position in which RFC 5321
specifies that a can appear. Although the characters in
the are permitted to contain non-ASCII characters, the
actual parsing of the and the delimiters used are
unchanged from the base email specification [RFC5321].

So perhaps this issue is invalid, and the latest specs are being followed. Is there any value in having two modes for email validation, one that accepts utf-8 characters in the local part, and another that does not?

diff --git a/src/FormatValidators.js b/src/FormatValidators.js
index 3406052..8d0aa29 100644
--- a/src/FormatValidators.js
+++ b/src/FormatValidators.js
@@ -47,7 +47,7 @@ var FormatValidators = {
         if (typeof email !== "string") {
             return true;
         }
-        return validator.isEmail(email, { "require_tld": true });
+        return validator.isEmail(email, { "require_tld": true, "allow_utf8_local_part": false });
     },
     "hostname": function (hostname) {
         if (typeof hostname !== "string") {

from z-schema.

shane-tomlinson avatar shane-tomlinson commented on September 14, 2024

Thanks @zaggino - closing this issue!

from z-schema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.