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     [CLOSED] Date Validation in Maintain Read/Write Grid.

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] Date Validation in Maintain Read/Write Grid.
 Login/Join
 
Guru
posted
Hi,
I have a Read/Write Grid in maintain in which there are few updatable columns which takes Date values from user in YYYY/MM/DD format to update the datasource.I want to do validation whether user enters correct value or not.I am using below piece of code to restrict user to enter value in correct format.
 
function OnGrid1_OnCellChange ( )  {
ClientRef.Grid1.UseMaskedEdit(1); // enable mask editing
ClientRef.Grid1.QuickSetMask (2, newRow, "0000/00/00");
}

function OnGrid1_OnEditFinish ( )  {
if ((col == 2) && (text.length != 10))
{
alert('Date can only be in YYYY/MM/DD format.');
}
}


But user can enter any incorrect value like '3333/33/33' and it will pass this validation but ideally its not a valid date.Is there any way to keep these things under check that user is entering valid date? What kind of validation is required to handle this? Please suggest.

Thanks in advance.

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


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML
 
Posts: 281 | Location: India | Registered: April 21, 2007Report This Post
Gold member
posted Hide Post
I have used a date validation routine that looks like this:

function CheckDate(date) {
 
   valid = true;
   var alertmsg = '' ;
 
   <!-- ensure in mm/dd/yyyy format -->
   if ((date.length != 10) || (date.substr(2,1) != '/') || (date.substr(5,1) != '/'))
      {
       valid = false;
       alertmsg = 'Invalid Date - format must be mm/dd/yyyy';
      }
 
  <!-- ensure a valid date -->
   if (valid)
      {
       var MM   = date.substr(0,2);
       var DD   = date.substr(3,2);
       var YYYY = date.substr(6,4);
       valid    = IsDate(YYYY, MM, DD);
       if (valid)
          {
           <!-- do nothing -->
          }
       else
          {
           alertmsg = 'Invalid Date - format must be mm/dd/yyyy';
          }
      }
 
  <!-- ensure not future date -->
   if (valid)
      {
      <!-- get today's date and convert to milliseconds using getTime to compare to newly selected date -->
       var Today      = new Date();
       var TodayCheck = Today.getTime();
 
      <!-- convert date to milliseconds using getTime to compare to today's date -->
       var NewDate      = new Date(YYYY, MM - 1, DD);
       var NewDateCheck = NewDate.getTime();
 
      <!-- check for a future date -->
       if (NewDateCheck > TodayCheck)
          {
           alertmsg = 'Invalid Date - date selected is in the future';
           valid    = false;
          }
      }
 
    return valid;
}
 
function IsDate(year, month, day) {
 
<!-- check for valid dates, javascript months are 0 through 11 -->
   month = month - 1;
 
   var calcDate = new Date(year,month,day);
 
   if ((year  == calcDate.getFullYear()) &&
       (month == calcDate.getMonth()) &&
       (day   == calcDate.getDate()))
        return true;
   else
        return false;
}



WebFOCUS 8
 
Posts: 74 | Location: Gahanna, OH | Registered: September 22, 2009Report This Post
Virtuoso
posted Hide Post
I use regular expressions in javascript for this:

Try this out:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Validate dd/mm/yyy date entry</title>
<script type="text/javascript">
function validDate(fld) {
    var wx=document.getElementById(fld.id);
    var RegExPattern = /^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/;
    var errorMessage = 'Please enter valid date as four digit year, month and day.\nYou may use a slash, a hyphen or a period to separate the date parts.';
    if ((wx.value.match(RegExPattern)) && (wx.value!='')) {
        return true;
    } else {
        alert(errorMessage);
    }
}
</script>
</head>
<body>
<form>
<p><input type="text" name="dateEntry" id="dateEntry" onchange="javascript:validDate(this);">
<br>(yyyy/mm/dd)
</form>
</body>
</html>


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report 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     [CLOSED] Date Validation in Maintain Read/Write Grid.

Copyright © 1996-2020 Information Builders