Date MM/DD/YYYY validation

  • caesss
  • caesss's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1

caesss created the topic: Date MM/DD/YYYY validation

i downloaded the script on this page

crosstec.org/support/index.php?pid=knowl...viewentclient&id=165

and i installed it but I noticed it didn't work. It was the same as DD/MM/YYYY. I compared it with the script for DD/MM/YYYY and it is the same (no change to the code), I think a file upload error. i tried changing the regular expression to

var pattern = /(0|1)[0-9]\x5C/[0-3][0-9]\x5C/(19|20)[0-9]{2}/\x3B\r\n

from

var pattern = /[0-3][0-9]\x5C/(0|1)[0-9]\x5C/(19|20)[0-9]{2}/\x3B\r\n

but it didn't work. What else am I missing?
#26351
  • caesss
  • caesss's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1

caesss replied the topic: Re: Date MM/DD/YYYY validation

I keep answering my own questions but here is the revised code in case somone else runs into the same problem.

just changed the regular expression and switch month and day

AND change the date_array (month should be 0 and day is 1)

done.


function ff_validate_date_MMDDYYYY(element, message)
{
// Regular expression used to check if date is in correct format
var pattern = /(0|1)[0-9]\/[0-3][0-9]\/(19|20)[0-9]{2}/;
if(pattern.test(element.value))
{
var date_array = element.value.split('/');
// Attention! Javascript consider months in the range 0 - 11
var month = date_array[0] - 1;
var day = date_array[1];
var year = date_array[2];

// This instruction will create a date object
source_date = new Date(year,month,day);

if(year != source_date.getFullYear())
{
return message == '' ? 'Element ' + element.name + ' failed my test' : message;
}

if(month != source_date.getMonth())
{
return message == '' ? 'Element ' + element.name + ' failed my test' : message;
}

if(day != source_date.getDate())
{
return message == '' ? 'Element ' + element.name + ' failed my test' : message;
}
}
else
{
return message == '' ? 'Element ' + element.name + ' failed my test' : message;
}

return '';
}
#26724
The following user(s) said Thank You: iCandy_Webs
  • Posts: 1
  • Thank you received: 0

jps replied the topic: Re: Date MM/DD/YYYY validation

I tried this script and ran into the problem of the "next" page button not working.
#57445
Moderators: ForumSupporttomeperica
Time to create page: 0.059 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Special Offer! Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for only 70!

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, WordPress® plugins, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here