Home > Uncategorized > How to: Validate Date Format Using Regular Expression

How to: Validate Date Format Using Regular Expression

Overview

 

There’re several different ways to handle Date values through the script, all depends on the exact need. In some cases, there’s a need to enter a date value manually, as text, yet to force it to be in a specific valid date format.

This article will show an example of how you can validate the date string format “DD/MM/YYYY” using a regular expression (to learn more on regular expressions, click here).

 

1. Step 1: Create an open ended question to hold the Date string format

2. Step 2: Add a validation rule for the format checking

 

Step 1: Create an open ended question to hold the Date string format

 

Add an open ended question to the script, where you want the Date value to be entered:

 

 

 

Step 2: Add a validation rule for the format checking

 

The Regular Expression that matches the format of DD/MM/YYYY is:

^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/([12][0-9]{3})$

 

** Note: The regular expression above matches date formats that refer only to the years range of 1000 – 2999

 

So, you can add this validation rule to the question:

And add the suitable error message as you wish, such as: “The date entered is not in the right format of DD/MM/YYYY. Please fix.”

 

** If you’re not familiar to validation rules, please click here to learn more.

 

That’s it!

 

Visit us at: http://www.dooblo.net

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: