Validate::minMaxNum let's me enter value below defined 'min'

Validate::minMaxNum let's me enter value below defined 'min'

CapamaniaCapamania Posts: 229Questions: 79Answers: 5
edited September 2016 in Editor

How can I only allow 0.0000 as the 'numeric' format ?

        Field::inst( '1m' )
            ->validator( 'Validate::numeric', array(
                "format"  => ,
                "message" => "This input must be given as a number as 0.0000"
            ) )

This question has an accepted answers - jump to answer

Answers

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5

    Never mind ... I formatted the mysql column to 0.0000

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5
    edited September 2016

    I'm now using minMaxNum:

            Field::inst( '1m' )
                ->validator( 'Validate::minMaxNum', array(
                    'min' => 0.00,
                    'max' => 100,
                    'message' => 'Please enter a number between 0.00 and 100'
                ) )
    

    ... but it still let's me enter a number below the defined 'min' e.g.

    0.001 -> returns: 0.00
    0.006 -> returns: 0.01

    How can I show a Default error message: 'Please enter a number between 0.00 and 100' if a value below the defined min is entered instead (and not round it up)? It's working with the 'max' if I enter a value higher than defined 'max' ... but not vice versa with 'min'

  • allanallan Posts: 61,833Questions: 1Answers: 10,133 Site admin

    Hi,

    I'm slightly confused I'm afraid. Are you saying that if you enter 0.001 you want an error? But that is greater than the defined minimum of 0.

    Allan

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5
    edited September 2016

    Ähh ... now I'm confused too :-)

    ... I just don't want them to enter more digits (here 2) after the decimal separator.

    So they can enter anything starting with

    0.00
    0.01
    0.02
    0.03
    ...

    But if they want to enter 3 digits after the decimal separator like
    0.001
    0.013
    0.026
    ...

    they should get an error message that they can only enter 2 digits after the decimal seperator ...

  • allanallan Posts: 61,833Questions: 1Answers: 10,133 Site admin
    Answer ✓

    Got it. So the issue is that 0.0000001 (or any other number of 0's) is in fact > 0, so the validator is in fact correct. What you need to to add extra validation. The built in validators don't have that ability though - you'd need to use a custom validator to check that the data is entered with a maximum of two decimal places.

    Allan

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5

    Oh yes, I guess I got a little confused here :-) Yet, a custom validator raises too many ? on my sight right now, so I will stick to the current solution which is fine. Thanks a lot.

This discussion has been closed.