Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Check for a valid date in a text field

Avatar

Level 4

Hello everybody!

I have a challenge that to me seems a bit tricky. I have a text field that appears as a comb of 11 characters. The user will enter digits in the format 999999-9999. Now I would like to check if the firs 6 digits are a valid date in the format ddmmyy. (the last 4 digits are random)

How can I do that?

Kirstine

1 Accepted Solution

Avatar

Correct answer by
Level 10

This needs to be tested THOROUGHLY. My testing was very limited. Given a two digit year the validation checks for two digits (\d\d) only.

// form1.page1.subform1.tf1::exit - (JavaScript, client)

if (!(this.isNull)) {

  var regEx = /^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])\d\d$/;

  var str = this.rawValue;

  str = str.substring(0,6);

  if (regEx.test(str)) {

    xfa.host.messageBox("Valid mmddyy");

  }

  else {

    xfa.host.messageBox("Invalid mmddyy");

  }

}

Steve

View solution in original post

3 Replies

Avatar

Level 10

Validate them using Regular Expression.

Nith

Avatar

Correct answer by
Level 10

This needs to be tested THOROUGHLY. My testing was very limited. Given a two digit year the validation checks for two digits (\d\d) only.

// form1.page1.subform1.tf1::exit - (JavaScript, client)

if (!(this.isNull)) {

  var regEx = /^(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])\d\d$/;

  var str = this.rawValue;

  str = str.substring(0,6);

  if (regEx.test(str)) {

    xfa.host.messageBox("Valid mmddyy");

  }

  else {

    xfa.host.messageBox("Invalid mmddyy");

  }

}

Steve

Avatar

Level 4

Hi Steve

Your script seams to do the job. Thanks a lot.

And to Nith,

Your point is all right. I just need more help than that as I’m a total newbie when it comes to scripting (any scripts at all) and I’m still not able to build my own scripts from scratch. It will come some day, I hope.

Regards,

Kirstine