svelte-forms_issue

Svelte Forms_issue

Validator email doesn't work

https://github.com/chainlist/svelte-forms/issues/75

Validator email doesn't work

See example of this issue with solution

The documentation for the email validator differs from code.

Documentation : email

function email() => { valid: boolean, name : 'email' };
import { field } from 'svelte-forms';
import { email } from 'svelte-forms/validators'; 
const name = field('name', '', [email()]);

Code :

../node_modules/svelte-forms/validators

export function email() {
    return (value) => {
        const regex = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
        return { valid: Boolean(value) && regex.test(value), name: 'not_an_email' };
    };
}

Since we have different names this validator can not work as explained in documentation.

From my point of view there are two possible solutions:

  1. in email.js file not_an_email should be replaced as email
  2. in documentation email should be replaced as not_an_email

Top categories

Loading Svelte Themes