Expand my Community achievements bar.

How i can chage the date formatt using java script?

Avatar

Level 3

Hi All,

I have a data field. In Object -> Valid patterns I changed the format as MM/DD/YYYY.

and i am writing the java script code on exit event of date field

 

var

reGoodDate = /^(?:(0[1-9]|1[012])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](19|20)[0-9]{2})$/

;

if (reGoodDate.test(dt))

{

xfa.host.messageBox("Correct format")

}

else

{

xfa.host.messageBox("Incorrect Format");

}

but though i am giving the correct date formatt it is giving  as error message

2 Replies

Avatar

Level 10

Hi,

try these regular expression instead.

if (this.formattedValue.match(/^(0[1-9]|1[012])[-\/\.](0[1-9]|[12][0-9]|3[01])[-\/\.]((19|20)\d{2}|\d{2})$/g)) {

          xfa.host.messageBox("Correct date");

} else {

          xfa.host.messageBox("Wrong date");

}