Equivalence in Editor Validation

Equivalence in Editor Validation

ayzayz Posts: 51Questions: 18Answers: 0

The example in "Ready to use field validators" section of your Editor Validation documentation, please confirm

Field::inst('email')
->validator(Validate::email(
ValidateOptions::inst()
->allowEmpty(false)
->optional(false)
) );

is exactly same as:

Field::inst('email')
->validator(Validate::email())
->validator(Validate::notEmpty())
->validator(Validate::required());

If so, is there any benefit of one style over the other?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    That is the case now.

    It used to be that the validators in PHP would give a validator specific error message if it failed, but with the introduction of ValidateOptions it became a generic error message (so it could be used by all).

    The advantage of the second way (I would chain it the other way around btw - check it is present before checking it is an e-mail address) is that you can give specific error messages for each validator.

    Allan

  • ayzayz Posts: 51Questions: 18Answers: 0

    2nd option is less head-twisting!

This discussion has been closed.