Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7733
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Simpler way to validate form fields? |
| Date | 2012-12-06 17:50 +0100 |
| Message-ID | <aic0lpFu3i7U1@mid.uni-berlin.de> (permalink) |
| References | (1 earlier) <ai8k28F62c0U1@mid.uni-berlin.de> <2m8ub8dm7cq38dbtorvlpbs4nq85h1q3gu@4ax.com> <ai8oanF70n6U1@mid.uni-berlin.de> <oagub8t658vanhdeajl0vgkvurn2ji7cve@4ax.com> <qr81c8d7bqr1u7gtum1ikb840ampn9ej2u@4ax.com> |
Am 06.12.2012 14:55, schrieb Gilles:
> On Thu, 06 Dec 2012 14:43:57 +0100, Gilles <nospam@nospam.com> wrote:
>
>> 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;
>> }
>
> I made a mistake, but even after turning $_POST into $_GET, it still
> displays nothing:
>
> function getDateFromForm($key, $l=8, $val=null) {
> //Check for date DD/MM/YYYY
> return (isset($_GET[$key])) ?
> filter_var(substr($_GET[$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");
I don't know offhand what exactly PHP makes of your GET URL, but be aware that the
forward slash is a path separator.
The regex is okay. Find ways to quickly test code bits, or functions, if possible
just use the command line. My test (newlines inserted for reading):
php > $d = "01/01/2112";
php > echo filter_var($d,
FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>"/^\d{2}\/\d{2}\/\d{4}/"))),
PHP_EOL;
01/01/2112
php > echo urlencode($d), PHP_EOL;
01%2F01%2F2112
Write regexp here with a different separator, easier to read:
array("regexp"=>"#^\d{2}/\d{2}/\d{4}#")
/Str.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-04 23:37 +0100
Re: Simpler way to validate form fields? "Beauregard T. Shagnasty" <a.nony.mous@example.invalid> - 2012-12-04 23:44 +0000
Re: Simpler way to validate form fields? Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-04 19:04 -0500
Re: Simpler way to validate form fields? Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-04 19:07 -0500
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-05 11:32 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-05 12:49 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-05 10:56 +0100
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-05 11:36 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-05 11:52 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-05 12:09 +0100
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-06 14:43 +0100
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-06 14:55 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-06 17:50 +0100
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-06 17:51 +0100
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-06 17:50 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-06 17:55 +0100
Re: Simpler way to validate form fields? Gilles <nospam@nospam.com> - 2012-12-07 11:15 +0100
Re: Simpler way to validate form fields? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-07 11:56 +0100
csiph-web