question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using validators to validate an email input

See original GitHub issue

PLEASE MAKE SURE THAT:

  • you searched similar issues online (9/10 issues in this repo are solved by googling, so please…do it)
  • you provide an online demo I can see without having to replicate your environment
  • you help me by debugging your issue, and if you can’t, do go on filling out this form

I’m submitting a … (check one with “x”)

[x ] bug report => search github for a similar issue or PR before submitting
[] support request/question

Notice: feature requests will be ignored, submit a PR if you'd like

Current behavior

When I’m trying to use validators to validate an email address, It gives me ‘ExpressionChangedAfterItHasBeenCheckedError’ from TagInputComponent.Html.

untitled

Expected behavior

Use validators to do our own validations. example - email, number or pattern matching.

Minimal reproduction of the problem with instructions (if applicable)

public validators = [this.emailValidation];

private emailValidation(control: any) { let sEmail = EmailValidator.validate(control.value); if (sEmail == false) { return { ‘emailValidation’: true }; } return null; }

What do you use to build your app?. Please specify the version

Webpack/ angular

Angular version:

5.0

ngx-chips version:

Latest as i installed it today (2018-05-01)

Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

All

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
SergeyMNetcommented, May 7, 2018

As for me all works fine.

in component ts


    public validators = [ this.must_be_email ];
    public errorMessages = {
        'must_be_email': 'Enter valid email adress!'
    };
    private must_be_email(control: FormControl) {        
        var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
        if (control.value != "" && (control.value.length <= 5 || !EMAIL_REGEXP.test(control.value))) {
            return { "must_be_email": true };
        }
        return null;
    }

in component html

<tag-input [ngModel]="emails"
        [errorMessages]="errorMessages" 
        [validators]="validators"
        [placeholder]="'Enter emails'" 
        [secondaryPlaceholder]="'Enter emails'">
    </tag-input>

Hope its helps you.

0reactions
gopinathrptcommented, Feb 1, 2019

As for me all works fine.

in component ts


    public validators = [ this.must_be_email ];
    public errorMessages = {
        'must_be_email': 'Enter valid email adress!'
    };
    private must_be_email(control: FormControl) {        
        var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
        if (control.value != "" && (control.value.length <= 5 || !EMAIL_REGEXP.test(control.value))) {
            return { "must_be_email": true };
        }
        return null;
    }

in component html

<tag-input [ngModel]="emails"
        [errorMessages]="errorMessages" 
        [validators]="validators"
        [placeholder]="'Enter emails'" 
        [secondaryPlaceholder]="'Enter emails'">
    </tag-input>

Hope its helps you.

suer

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="email"> - HTML: HyperText Markup Language
When you create an email input with the proper type value, email , you get automatic validation that the entered text is at...
Read more >
Validating email addresses - The complete HTML5 tutorial
Using patterns to validate email addresses. Another way to validate email addresses is to use the pattern attribute. As mentioned in the chapter...
Read more >
html - HTML5 Email Validation - Stack Overflow
Regex checks have too many flaws. The best way to "validate" an email addresses is to simply have them type it twice and...
Read more >
How to Do an Email Validation in JavaScript? - Simplilearn
Define a regular expression for validating email address · Check if the input value matches with regular expression · If it does match,...
Read more >
Simple guide to HTML Email Validation - Abstract API
HTML5 validation made easy. A simple guide to using the email attribute in HTML. We include code examples, regex patterns, and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found