PHP Classes

RegExp \d Bug

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Locating addresses on...  >  All threads  >  RegExp \d Bug  >  (Un) Subscribe thread alerts  
Subject:RegExp \d Bug
Summary:\d wont validate server side
Messages:3
Author:seidmh
Date:2006-12-27 23:57:13
Update:2006-12-28 01:27:05
 

  1. RegExp \d Bug   Reply   Report abuse  
Picture of seidmh seidmh - 2006-12-27 23:57:13
I have the following RegExp validating a text box for a date.

"ValidateRegularExpression"=>"2\d\d\d-([1-9]|0[1-9]|1[012])-([1-9]|0[1-9]|[12][0-9]|3[01])",
"ValidateRegularExpressionErrorMessage"=>"Enter a valid date (yyyy-mm-dd)."

It works with the javascript, but then it fails on the server side.

I think it is a problem with \d because the following works on both javascript and on the server side: "2[0-9]{3}-([1-9]|0[1-9]|1[012])-([1-9]|0[1-9]|[12][0-9]|3[01])"


  2. Re: RegExp \d Bug   Reply   Report abuse  
Picture of seidmh seidmh - 2006-12-28 01:22:30 - In reply to message 1 from seidmh
Nevermind, I read your previous post about POSIX regular expressions.

  3. Re: RegExp \d Bug   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-28 01:27:05 - In reply to message 1 from seidmh
That is not really a bug of the class, but rather about differences of implementation between PHP POSIX and Javascript regular expressions.

In POSIX it should be [:digit:] and Javascript should be \d . Since neither work on both sides, it is recommended that you stick to [0-9] .