How can I set 2 validations for one field?
How can I set 2 validations for one field?
I want to validate that the input is numeric AND not empty (the user is required to enter a number in this particular field).
I have tried following codes, but they all bring up an Ajax error:
Field::inst( 'number' )
->validator( 'Validate::numeric' ),
->validator( 'Validate::required' ),
(...)
Field::inst( 'number' )
->validator( 'Validate::numeric', array('required'=>true) ),
(...)
Could anybody please give me some clue on how this can be done?
This question has accepted answers - jump to:
Answers
Currently only a single validator can be used for a field at a time, although Editor 1.4 will change that...
As such, the second option you specify is the way to do this at the moment. You note that it gives an error - what is the Ajax response? Likely there is an error message in it.
Allan
Ok, I see...
The error I get is this; http://datatables.net/manual/tech-notes/7
I had to remove one of the two parameters.
Thanks for the info :-)
I just tried the second option again, and curiously I don't get that error anymore :o
But it only validates the "required" condition, it doesn't complain when the input is non-numeric (despite of the parameter 'Validate::numeric'). Maybe I am doing something wrong...
I've just tried this in my examples:
And it appears to correctly validate as a number and is a required field.
Something is going wrong somewhere, but I think I'd need to be able to see your PHP and Javascript to understand what exactly. Can you link me to the page and also show the PHP?
Allan
The page is http://bendsito.net/2black/index.html
And the PHP is the following:
The field 'n_socio' is the one I'm having trouble with this double validation.
The validation applied to that field at the moment is:
so it is required, required :-)
Do you not want:
?
Allan
After so many changes and testing, I'm not sure why I did that :D
Your code is exactly what I want, and it works now :-) Thanks a lot!
Good to hear that works!
Allan
Thanks Allan, you help me too !