Switching validators on the same field

In general, a field might have different validators. Based on various conditions, some of them can be turned on, and the remaining are turned off.

For instance, the following form asks user to fill in a number which must be a valid Brazilian ID (known as CPF) or VAT (known as CNPJ) number. CPF and CNPJ numbers have 11 and 14 characters respectively. Based on the length of input, we can guess which type of number user is trying to put in.

Firstly, use the enabled option to enable (disable) validators initially

Lastly, turn on (off) the validators based on the length of field:

More examples

Related validators

The following validators might be useful to you.