Multiple Validators

Multiple Validators

DatagaardDatagaard Posts: 68Questions: 20Answers: 3

I want to be able to validate a numeric field that will allow a null value.

I can't seem to get the right combination of option settings.

Tried this:

Field::inst( 'CMBSCodes.MaxClaimAmount' )
            ->validator( 'Validate::empty',true)
            ->validator( 'Validate::numeric' )

But I receive an Error in the Editor, with no message when I leave the field which is null untouched.

Or have I misinterpreted the validation options manual!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I think you just need:

    Field::inst( 'CMBSCodes.MaxClaimAmount' )
                ->validator( 'Validate::numeric' )
    

    Editor's PHP validators have a "common" validation and an empty check is part of that. The default is to allow a null value if it is optional.

    Allan

This discussion has been closed.