• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Calendar javascript doesn't allow minutes seconds

I have the tigra calendar date picker (free) on my site, but have modified my field to allow a default time entry.  The calendar applies it just fine, but when I try to update it throw the "wrong format" error.  The authentication code is below...I know I need to change the re_date variable, but what do I change it to to allow mm/dd/yyyy hh:mm:ss AM (for example: 05/15/2011 8:00:00 AM)?

var re_date = /^\s*(\d{1,2})\/(\d{1,2})\/(\d{2,4})\s*$/;
 
      if (!re_date.exec(s_date))
            return alert ("Invalid date: '" + s_date + "'.\nAccepted format is mm/dd/yyyy.")
      var n_day = Number(RegExp.$2),
            n_month = Number(RegExp.$1),
            n_year = Number(RegExp.$3);
      
      if (n_year < 100)
            n_year += (n_year < this.a_tpl.centyear ? 2000 : 1900);
      if (n_month < 1 || n_month > 12)
            return alert ("Invalid month value: '" + n_month + "'.\nAllowed range is 01-12.");
      var d_numdays = new Date(n_year, n_month, 0);
      if (n_day > d_numdays.getDate())
            return alert("Invalid day of month value: '" + n_day + "'.\nAllowed range for selected month is 01 - " + d_numdays.getDate() + ".");

      return new Date (n_year, n_month - 1, n_day);
}
0
Kevin Smith
Asked:
Kevin Smith
  • 5
  • 4
1 Solution
 
eugenbvCommented:
A true date time regex should be more complicated that the one you have.

Please try this for
var re_date

(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$

Open in new window

0
 
Kevin SmithAuthor Commented:
Dreamweaver is reporting a syntax error...
0
 
eugenbvCommented:
did you enclosed the pattern in quotes ?

var re_date = '(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$';
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
eugenbvCommented:
Also you might want to look at
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
on how to use regex in javascript.
0
 
Kevin SmithAuthor Commented:
yea...it just doesn't open on the page now.
0
 
Kevin SmithAuthor Commented:
Unless the field is empty of course, then it opens.
0
 
eugenbvCommented:
Have you tried this
var re_date = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/i;

Open in new window

can you post html if this doesn't work?
0
 
Kevin SmithAuthor Commented:
Ah, something different, but still funky...it says undefined on the month area and just shows the days of week headings, no dates.

This is the html...

<input type="text" name="startdate" value="<%=(hupdate.Fields.Item("startdate").Value)%>" size="20" onChange="changestartdate()" />
                          <script language="JavaScript" type="text/javascript">
      new tcal ({
            'formname': 'form1',
            'controlname': 'startdate'
      });
                      </script>
0
 
eugenbvCommented:
Check this out. A full html test page that I've built.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<title>Tigra Calendar Sample #1 - Simple Form</title>

	
<!-- link calendar files  -->
	<script language="javascript" src="calendar_us.js" type="text/javascript"></script>
	
<link rel="stylesheet" href="calendar.css">

	
</head>
<body>



<form name="testform">

	
<!-- calendar attaches to existing form element -->
	
<input type="text" id="text" name="testinput" />
	
<input type="button" onclick="checkDate();" value="submit" />
<script language="javascript" type="text/javascript">
	
function checkDate()
{
     
     var s_date = document.getElementById('text').value;
      var re_date = /(?=\d)^(?:(?!(?:10\D(?:0?[5-9]|1[0-4])\D(?:1582))|(?:0?9\D(?:0?[3-9]|1[0-3])\D(?:1752)))((?:0?[13578]|1[02])|(?:0?[469]|11)(?!\/31)(?!-31)(?!\.31)|(?:0?2(?=.?(?:(?:29.(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|(?:0?2(?=.(?:(?:\d\D)|(?:[01]\d)|(?:2[0-8])))))([-.\/])(0?[1-9]|[12]\d|3[01])\2(?!0000)((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?!\x20BC)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/i;
      if (!re_date.exec(s_date))
            return alert ("Invalid date: '" + s_date + "'.\nAccepted format is mm/dd/yyyy.")
      var n_day = Number(RegExp.$3),
            n_month = Number(RegExp.$1),
            n_year = Number(RegExp.$4);
      
      if (n_year < 100)
            n_year += (n_year < this.a_tpl.centyear ? 2000 : 1900);
      if (n_month < 1 || n_month > 12)
            return alert ("Invalid month value: '" + n_month + "'.\nAllowed range is 01-12.");
      var d_numdays = new Date(n_year, n_month, 0);
      if (n_day > d_numdays.getDate())
            return alert("Invalid day of month value: '" + n_day + "'.\nAllowed range for selected month is 01 - " + d_numdays.getDate() + ".");

      return new Date (n_year, n_month - 1, n_day);
}

new tcal ({
		
// form name
		
'formname': 'testform',
		
// input name
		
'controlname': 'testinput'
	
});


	
</script>

</form>


</body>

</html>

Open in new window



Hope it solves your problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now