Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] email validator doesn't work #75

Closed
BogdanGorelkin opened this issue Mar 29, 2022 · 2 comments
Closed

[BUG] email validator doesn't work #75

BogdanGorelkin opened this issue Mar 29, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@BogdanGorelkin
Copy link

Validator email doesn't work

this will not work:
$myForm.hasError('name.email')

this will work:
$myForm.hasError('name.not_an_email')

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
@BogdanGorelkin BogdanGorelkin added the bug Something isn't working label Mar 29, 2022
@chainlist
Copy link
Owner

Hi,

Thanks for the bug report, it was a wording choice from me, i don't know what i was thinking back then.
I'll change this ASAP.

@ecker00
Copy link

ecker00 commented Jun 27, 2022

Seems that this behavior is still present in v2.3.1, assume once a new version is up on NPM this validation will be called email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants