Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Guided Ad-hoc tool needs javascript to validate date entry
Go
New
Search
Notify
Tools
Reply
  
[SOLVED] Guided Ad-hoc tool needs javascript to validate date entry
 Login/Join
 
Gold member
posted
Does anyone have any good ideas on how to validate Date (calendar) controls in a guided ad-hoc HTML page?

I've googled javascript and I am clueless. I try to follow the script but I don't know which portions of the code have to be customized with my control names, etc.

I have so many problems with users not entering the date in mm/dd/yyyy even though I specifically state it on the screen.

Any suggestions would be awesome!

This message has been edited. Last edited by: jseaburn,


WebFOCUS 7.7.03
Linux / Universe Db
HTML/PDF/EXCEL/HTML Active
 
Posts: 90 | Registered: November 03, 2009Reply With QuoteReport This Post
Virtuoso
posted Hide Post
maybe search would help you on this issue

I did it for you and found this one

but there are some more




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Reply With QuoteReport This Post
Gold member
posted Hide Post
Hi Frank,

I actually did do a search and read that thread before I posted this question. That one is populating the control with a default date - I just want to validate what my user enters.

I also searched on google and found some javascript code, but I'm not good with figuring out which part of the code I need to customize for my own controls.


WebFOCUS 7.7.03
Linux / Universe Db
HTML/PDF/EXCEL/HTML Active
 
Posts: 90 | Registered: November 03, 2009Reply With QuoteReport This Post
Master
posted Hide Post
Firstly, if you use a calendar control, won't that fill in the date in a format selected in the chooser? I know we have several examples of the text box portion of the control being disabled and only filled in via the calendar control pop-up.

Secondly, the indexOf function in javascript will look for occurrences of a value in a string. Check out http://www.w3schools.com/jsref/jsref_IndexOf.asp You'll have to determine presence of both slashes in positions 3 and 6 (based on your stated format).

Thirdly, you would then have to substring it to break down the tokens and determine if they are in the realm of reasonability given the token's representation (the first 2 chars are between 01 and 12). Check out http://www.w3schools.com/jsref/jsref_substring.asp If you implement the IndexOf as stated above, you may be able to get away with looking solely at the position.

Lastly, check out this article as it seems like it may do what you want already: http://www.codeproject.com/Tip...tion.aspx#alternate1

Hope this helps.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
 
Posts: 561 | Registered: February 03, 2010Reply With QuoteReport This Post
Gold member
posted Hide Post
Thank you for the suggestion! w3schools is actually a site that I use.

We don't have the text box disabled because our users are moving from an environment where they are used to typing in the date. So the calendar is available as an option, but I think my users are split on whether they use it or not.

I did manage to come up with a solution and I will share it soon for anyone else that might need to do this.

Thank you!


WebFOCUS 7.7.03
Linux / Universe Db
HTML/PDF/EXCEL/HTML Active
 
Posts: 90 | Registered: November 03, 2009Reply With QuoteReport This Post
Expert
posted Hide Post
  
//--------------------------------------------------------------------------
//This function validates the date for MM/DD/YYYY format.
//--------------------------------------------------------------------------
function isValidDate(dateStr) {

 // Checks for the following valid date formats:
 // MM/DD/YYYY
 // Also separates date into month, day, and year variables
 var datePat = /^(\d{2,2})(\/)(\d{2,2})\2(\d{4}|\d{4})$/;
 
 var matchArray = dateStr.match(datePat); // is the format ok?
 if (matchArray == null) {
  alert("Date must be in MM/DD/YYYY format")
  return false;
 }
 
 month = matchArray[1]; // parse date into variables
 day = matchArray[3];
 year = matchArray[4];
 if (month < 1 || month > 12) { // check month range
  alert("Month must be between 1 and 12");
  return false;
 }
 if (day < 1 || day > 31) {
  alert("Day must be between 1 and 31");
  return false;
 }
 if ((month==4 || month==6 || month==9 || month==11) && day==31) {
  alert("Month "+month+" doesn't have 31 days!")
  return false;
 }
 if (month == 2) { // check for february 29th
  var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
  if (day>29 || (day==29 && !isleap)) {
   alert("February " + year + " doesn't have " + day + " days!");
   return false;
    }
 }
 return true;  // date is valid
}

This message has been edited. Last edited by: Tom Flynn,


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1965 | Location: Centennial, CO | Registered: January 31, 2006Reply With QuoteReport This Post
Gold member
posted Hide Post
That's a good one Tom!! It checks for more things than mine does.

Thanks!

Good One


WebFOCUS 7.7.03
Linux / Universe Db
HTML/PDF/EXCEL/HTML Active
 
Posts: 90 | Registered: November 03, 2009Reply With QuoteReport This Post
Expert
posted Hide Post
Welcome...

Have Fun!


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1965 | Location: Centennial, CO | Registered: January 31, 2006Reply With QuoteReport This Post
Master
posted Hide Post
Nice succinct regex's Tom.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
 
Posts: 561 | Registered: February 03, 2010Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Guided Ad-hoc tool needs javascript to validate date entry

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.