/    Sign up×
Community /Pin to ProfileBookmark

Need to find the correct regex

hello

I need to make a check using regex inside one date field (under Joomla) but after making some test by following the regex docs I found here

[url]http://www.zytrax.com/tech/web/regex.htm[/url]

and here:

[url]http://www.regular-expressions.info/tutorial.html[/url]

..I’m always unable to find the correct one without getting an error.

In fact my goal is to check if my date field is filled with a value or not. When no value is filled, the field by default use this exact value:

0000-00-00

and in some case the field is left blank/empty (null).

So in practice I need to check if my date field contain [B]0000-00-00[/B] OR nothing.

If I’m not wrong for be able to use OR operator I must use the | for separate my value. So for example I tried this:

0000-00-00|
000-00-00|
000-00-00|
[0000-00-00]|
[0000-00-00]|

but none of them let me to make this check…I get always an error.

Anybody have some suggestion to how I must write my regex??

thank

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@slyfoxJul 20.2011 — bit rusty on the regex...

how about just counting it all up... if the result is '0', you have your answer ?

... just a thought
Copy linkTweet thisAlerts:
@dotcom22authorJul 20.2011 — thank for suggestion but unfortunately is not so simple.

My goal in fact is to hide the birth date in the user profile if this field is not filled. I discover recently depending how the user register to my site (using the default registration process or Facebook connect), the value included inside database is not the same for this data field.

Sometime the value is 0000-00-00 OR nothing reason why I need to make a check to this exact value for hide the field. I use a component who already do anything about a field but I can use only one operator and not multiple (like AND/OR) for the same field. The only way I have without re-inventing the wheal is to use regex but I need to find the correct syntax...
Copy linkTweet thisAlerts:
@DerokorianJul 20.2011 — Change the column to NOT NULL, and update all records set to nothing to be set to 0000-00-00 so you only have one thing to check for?
Copy linkTweet thisAlerts:
@slyfoxJul 20.2011 — so when you get you values back from fbquery, use strtotime to check if there's anything valid in there, it should return false if no date or zero at least

see this page:

http://php.net/manual/en/function.strtotime.php

I'm thinking along the lines of a php function that does something like "isDate"... should be much easier to find than regex solution
Copy linkTweet thisAlerts:
@ericatekkaJul 20.2011 — [code=php]if(!empty($_POST['dateofbirth']) && strtotime($_POST['dateofbirth']) !== "0"){
echo "TRUE";
}else{
die();
}[/code]

Just a guess.
Copy linkTweet thisAlerts:
@dotcom22authorJul 20.2011 — many thank to all for your suggestions..

In fact I finally found the correct regex I need. Here the solution:

/^0000-00-00|NULL|A.{0,0}z$/i

cheers
×

Success!

Help @dotcom22 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...