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


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