RegExp Date Wizard

By James KanjoJames Kanjo

Description

Sometimes we have specific syntax requirements for when our users provide us input. For example, lets say we wanted to user to enter a number… if the user enters a letter, we want an error message to inform them that they haven't entered a number.

In Wikidot, we are given the ability to use Regular Expressions (RegExp) to ensure our users enter the correct data inside textboxes (including when creating new pages, data forms or even mail forms).

Creating a RegExp to validate a user's input for a date, is no easy task. Why not? Because the RegExp needs to account for the fact that not every month in the year has 31 days. It also needs to account for the fact that February has only 28 days. And, of course, it needs to account for February's 29th day during leap years only.

With this Wizard, you can generate a RegExp for validating Dates according to the syntax you specify.

And yes, it does account for days in the month, and leap years.

Code

After specifying your date syntax below, the RegExp is automatically generated for you to copy and paste from the “RegExp Code” box.

You can also test the RegExp by typing a date into the “Test RegExp” text box.

Also be aware that the generated RegExp only accepts days and months with two digits (the 1st of September = 01 of 09).


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by James Kanjo

Extended NewPage Module - 15 Jul 2014 15:08
Specific Users Only Include - 24 Jul 2013 06:16
iframe Redirect - 30 Jul 2012 22:41
Per Category CSS Module - 06 Mar 2012 03:38
Video Player - 16 Feb 2012 01:50
Remove Duplications - 16 Feb 2012 01:39
"Random Page!" link - 16 Feb 2012 01:35
Quoted Blockquotes - 16 Feb 2012 01:33
NewPage Button - 16 Feb 2012 01:26
MP3 Player - 16 Feb 2012 01:25
JavaScript Addition - 16 Feb 2012 01:14
iframe embed - 16 Feb 2012 01:08
Random Page - 18 May 2011 09:50
Redirect - 11 Feb 2010 10:00


Rate this solution

If you think this solution is useful — rate it up!

rating: +6+x
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License