Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #7736

Re: Simpler way to validate form fields?

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:55 +0100
Message-ID <aic0vpFu5u3U1@mid.uni-berlin.de> (permalink)
References (2 earlier) <2m8ub8dm7cq38dbtorvlpbs4nq85h1q3gu@4ax.com> <ai8oanF70n6U1@mid.uni-berlin.de> <oagub8t658vanhdeajl0vgkvurn2ji7cve@4ax.com> <qr81c8d7bqr1u7gtum1ikb840ampn9ej2u@4ax.com> <m6h1c8t93qrlcpsc7lpsvqmbd8ook9ldov@4ax.com>

Show all headers | View raw


Am 06.12.2012 17:50, schrieb Gilles:
> On Thu, 06 Dec 2012 14:55:51 +0100, Gilles <nospam@nospam.com> wrote:
>> 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");
> 
> Turns out I should have used "/^\d{2}\/\d{2}\/\d{4}$/". Regardless,
> this doesn't check that the date looks kosher, eg. 99/99/9999 is
> considered OK, so it looks like it's loetter to use something else
> such as:
> 
> if (DateTime::createFromFormat('d/m/Y', $string))

The date verification problems are a all time favorite in programming.

But to the regular expression: they just pick the pattern where they find it, so this
is always a tolerant and save input reading. You might as well leave off the ^ and $
delimiters.

/Str.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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