Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


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

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[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, 2009Report 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, 2006Report 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, 2009Report 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, 2010Report 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, 2009Report 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: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report 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, 2009Report This Post
Expert
posted Hide Post
Welcome...

Have Fun!


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report 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, 2010Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

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-2020 Information Builders