date format as MM/DD/YYYY?

Avatar

Avatar
Validate 25
Level 2
mmgiath
Level 2

Likes

6 likes

Total Posts

321 posts

Correct reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 2
mmgiath
Level 2

Likes

6 likes

Total Posts

321 posts

Correct reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
mmgiath
Level 2

10-11-2016

How I can force a user to enter in a text field date format as MM/DD/YYYY?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

397 likes

Total Posts

2,687 posts

Correct reply

492 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

397 likes

Total Posts

2,687 posts

Correct reply

492 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
radzmar
MVP

23-11-2016

You can use FormCalc to check, if the entered text is a valid date.

Add this script in the exit event of your text field. Ensure the selected programming language is FormCalc not JavaScript.

if (Date2Num(Parse("DD/MM/YYYY", $), "YYYY-MM-DD") eq 0) then

  if ($host.messageBox("Enter a Date in the format DD/MM/YYYY.", "Wrong Date", 0, 0) eq 1) then

  $host.setFocus($.somExpression)

  endif

endif

Answers (4)

Answers (4)

Avatar

Avatar
Validate 25
Level 2
mmgiath
Level 2

Likes

6 likes

Total Posts

321 posts

Correct reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 2
mmgiath
Level 2

Likes

6 likes

Total Posts

321 posts

Correct reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
mmgiath
Level 2

23-11-2016

Hi, I am using this method(text field) because users they have to enter their date of birth. I do not know any other method..to use.

Is it possible to modify the script to enter the date as DD/MM/YYYY?

Thank you very much

Avatar

Avatar
Validate 1
Level 1
Archyron
Level 1

Likes

2 likes

Total Posts

7 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Archyron
Level 1

Likes

2 likes

Total Posts

7 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Archyron
Level 1

22-11-2016

If you're trying to enter a date I don't see why you would want to use a text field over a date field. However, if you absolutely need a text field you could use regex in the validate event like so:

if (!(this.isNull || this.rawValue.length == 0)) {

  //Test for MM/DD/YYYY format

  var pattern = new RegExp("^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/\d{4}$","g");

  var isMatch = pattern.test(this.rawValue);

  if(!isMatch)

       xfa.host.messageBox("The date you entered is in an incorrect format", "Error");

}

//Disables validation trigger

true;

To reiterate, I highly discourage you from using this method. It is incomplete since you can still enter dates like 02/30/2000 which would obviously be invalid.

Avatar

Avatar
Validate 25
Level 2
mmgiath
Level 2

Likes

6 likes

Total Posts

321 posts

Correct reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 2
mmgiath
Level 2

Likes

6 likes

Total Posts

321 posts

Correct reply

0 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
mmgiath
Level 2

11-11-2016

The field I am using is a text field not a date filed.

I need a script to notify users in order to enter the correct format.

Thank you

Avatar

Avatar
Validate 1
Level 1
Archyron
Level 1

Likes

2 likes

Total Posts

7 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
Archyron
Level 1

Likes

2 likes

Total Posts

7 posts

Correct reply

2 solutions
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
Archyron
Level 1

10-11-2016

Use the validation pattern: date{MM/DD/YYYY}