Re: Simpler way to validate form fields? [message #179799 is a reply to message #179797] |
Thu, 06 December 2012 13:43 |
Gilles Ganault
Messages: 27 Registered: September 2010
Karma:
|
Junior Member |
|
|
On Wed, 05 Dec 2012 12:09:11 +0100, "M. Strobel"
<sorry_no_mail_here(at)nowhere(dot)dee> wrote:
> One more observation to the default value val:
>
> with getIntFromForm() the settable default is especially useful, because PHP likes to
> return integer 0 for an empty input.
Thanks for the input. I modified the above to check for a dd/mm/yyyy
date, but PHP returns nothing so I guess I'm using filter_var()
wrongly with its regex option:
==============
#!"C:\Projects\Php\dummyl\php-cgi.exe"
<?php
function getDateFromForm($key, $l=8, $val=null) {
//Check for date DD/MM/YYYY
return (isset($_POST[$key])) ?
filter_var(substr($_POST[$key],0,$l),
FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>"/^\d{2}\/\d{2}\/\d{4}/ "))
)
: $val;
}
//http://192.168.0.1/test.php?mydate=01/02/2012
print getDateFromForm("mydate");
==============
Thank you.
|
|
|