Expected validator to return Promise or Observable

Im trying to do a custom validation on Angular 5 but I’m facing the following error

Expected validator to return Promise or Observable

I just want to return an error to the form if the value doesnt match the required, heres my code:

This is the component where is my form

  constructor(fb: FormBuilder, private cadastroService:CadastroService) {
    this.signUp = fb.group({
      "name": ["", Validators.compose([Validators.required, Validators.minLength(2)])],
      "email": ["", Validators.compose([Validators.required, Validators.email])],
      "phone": ["", Validators.compose([Validators.required, Validators.minLength(5)])],
      "cpf": ["", Validators.required, ValidateCpf]
    })     
   }

This code is in the file with the validation I want to implement:

import { AbstractControl } from '@angular/forms';

export function ValidateCpf(control: AbstractControl){
    if (control.value == 13445) {
        return {errorCpf: true}
    }
    return null;
}

Can someone help me? Does that type of validation only work with observables or can I do i without being a promise or observable? thanks

134 thoughts on “Expected validator to return Promise or Observable”

  1. Hi there, just became aware of your blog through
    Google, and found that it’s truly informative.
    I am gonna watch out for brussels. I’ll appreciate if you continue this in future.

    A lot of people will be benefited from your writing.
    Cheers!

    Reply
  2. Hi! I know this is kinda off topic nevertheless I’d figured I’d ask.
    Would you be interested in trading links or maybe guest authoring a blog article or vice-versa?

    My blog goes over a lot of the same subjects as yours
    and I feel we could greatly benefit from each other. If you might be
    interested feel free to send me an email. I look forward to hearing from you!
    Great blog by the way!

    Reply
  3. Pingback: best nuts for keto
  4. I’m not sure where you are getting your information, but good topic.
    I needs to spend some time learning more or understanding more.
    Thanks for magnificent info I was looking for this info for my mission.

    Reply
  5. Admiring the hard work you put into your site and in depth information you offer.
    It’s good to come across a blog every once in a while that isn’t the same unwanted rehashed material.
    Excellent read! I’ve saved your site and I’m including your
    RSS feeds to my Google account.

    Reply
  6. Hey! I know this is kinda off topic but I was wondering
    if you knew where I could locate a captcha plugin for my comment form?
    I’m using the same blog platform as yours and I’m having difficulty finding
    one? Thanks a lot!

    Reply
  7. Have you ever considered publishing an e-book or guest authoring on other sites?
    I have a blog based upon on the same information you discuss and would
    love to have you share some stories/information. I know my readers would
    value your work. If you’re even remotely interested, feel free
    to shoot me an email. ps4 games https://bit.ly/3z5HwTp ps4

    Reply
  8. Howdy! I know this is kinda off topic however I’d figured I’d ask.
    Would you be interested in exchanging links or maybe guest writing a blog
    article or vice-versa? My blog addresses a lot
    of the same topics as yours and I believe we could greatly benefit from
    each other. If you are interested feel free to send
    me an e-mail. I look forward to hearing from you!
    Excellent blog by the way!

    Reply
  9. Howdy! This blog post couldn’t be written any better! Looking through this post reminds me of my previous roommate!

    He constantly kept preaching about this. I most certainly will
    forward this post to him. Pretty sure he’s going to have a great read.
    Thanks for sharing!

    Reply
  10. Heya i’m for the first time here. I found this board and I find It really
    useful & it helped me out much. I hope to give something back and aid others like you aided me.

    Reply
  11. Hi would you mind stating which blog platform you’re using?
    I’m planning to start my own blog in the near future but I’m having a tough time choosing between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m looking for something unique.

    P.S Sorry for being off-topic but I had to ask!

    Reply
  12. Just that, I got measure up A service as they were the alone district to be enduring both Rims and azithromycin drug class for the purpose a revitalized to make available vehicle. The transport was winged and hands down to track. These rims look so substantial I fancy them on my all seasons and not my winters. Looks like I desire be getting a new home of rims again soon.

    Reply

Leave a Comment