set multiple validator patterns for a single textbox based on user input

Discussão em 'Angular' iniciado por xrx215, Novembro 27, 2024.

  1. xrx215

    xrx215 Guest

    Here is the formcontrol I am using. If the user enters Country US i need to set the validator as shown below (min length 5 max length 12)

    lblzip1 = new FormControl('', Validators.compose([
    Validators.required,
    this.noWhitespaceValidator,
    Validators.pattern('^[a-zA-Z0-9- ]{5,15}$')
    ]));


    IF the user enters any other country other than US I need to set the validator as shown below (min length 1, mx length 15)

    lblzip1 = new FormControl('', Validators.compose([
    Validators.required,
    this.noWhitespaceValidator,
    Validators.pattern('^[a-zA-Z0-9- ]{1,15}$')
    ]));


    Can you please let me know how do we do this in angular?

    Continue reading...

Compartilhe esta Página