How can I validate a date field in Portal Forms

I have a date field in portal forms that I want to perform validation on to make sure it's in the proper format before being accepted (mm/dd/yyyy). How can I validate against that field?

Hi Ben,
I took the time to test and revise. This is code that will validate a date entry (format MM/DD/YYYY). Just paste this in the "Before the start of the form..." window of the Additional PL/SQL code section of the form. Then add validateDate(); into the onBlur event window of the field in question. Replace the CYCLE_END_DATE with the field name in question.
HTP.P('
<SCRIPT LANGUAGE=javascript>
function validateDate() {
var ddObj;
var mmObj;
var yyObj;
var day;
var mon;
var year;
var field_val;
var field_name;
for (var j=0; j < document.forms[0].elements.length; j++) {
field_name = document.forms[0].elements[j].name;
field_val = document.forms[0].elements[j].value;
if (field_name.substring(field_name.indexOf(''DEFAULT.'') + 8, field_name.lastIndexOf(''.01'')) == ''CYCLE_END_DATE'') {
var delimPos = field_val.search(/\//i);
if (delimPos < 0)
alert(''Invalid date entry! Please enter in MM/DD/YYYY format. '' +
''e.g, Dec 21, 2003 would be entered as 12/21/2003'');
else
if (field_val.length != 10)
alert(''Invalid date entry! Please Please enter in MM/DD/YYYY format. '' +
''e.g, Jan 1, 2003 would be entered as 01/01/2003'');
else {
month = field_val.substring(0, field_val.indexOf(''/''));
day = field_val.substring(field_val.indexOf(''/'') + 1, field_val.lastIndexOf(''/''));
year = field_val.substring(field_val.lastIndexOf(''/'') + 1, 10);
/* Need to subtract 1 from value because in Javascript, January begins with 0
and ends with 11 for December */
month = month - 1;
ddObj = new Date(year, month, day);
mmObj = new Date(year, month, day);
yyObj = new Date(year, month, day);
if (ddObj.getDate(ddObj.setDate(day)) != day)
alert(''Invalid day!'');
if (mmObj.getMonth(mmObj.setMonth(month)) != month)
alert(''Invalid month!'');
if (mmObj.getYear(mmObj.setYear(year)) != year)
alert(''Invalid year!'');
</SCRIPT>
');

Similar Messages

  • How can I validate a date using sql

    How can I validate a date using sql or pl/sql
    select to_date('01/01/2009','mm/dd/yyyy') from dual this is a good date
    but how can I check for a bad date
    select to_date('0a/01/2009','mm/dd/yyyy') from dual
    Howard

    William Robertson wrote:
    It'll be complicated in pure SQL, as you'll have to parse out day, month and year and then validate the day against the month and year bearing in mind the rules for leap years. It would be simpler to write a PL/SQL function and call that.Nah, not that complicated, you just need to generate a calender to validate against.
    SQL> ed
    Wrote file afiedt.buf
      1  with yrs as (select rownum-1 as yr from dual connect by rownum <= 100)
      2      ,mnth as (select rownum as mn, case when rownum in (4,6,9,11) then 30
      3                            when rownum = 2 then 28
      4                       else 31
      5                       end as dy
      6                from dual
      7                connect by rownum <= 12)
      8      ,cent as (select (rownum-1) as cen from dual connect by rownum <= 21)
      9      ,cal as (select cen, yr, mn,
    10                      case when ((yr = 0 and mod(cen,400) = 0)
    11                             or (mod(yr,4) = 0 and yr > 0))
    12                            and mn = 2 then dy+1
    13                      else dy
    14                      end as dy
    15               from cent, yrs, mnth)
    16  --
    17      ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    18  --
    19  select case when cal.cen is null then 'Invalid Date'
    20              when not regexp_like(dt,'^[0-9]{1,2}[\/.-_][0-9]{1,2}[\/.-_][0-9]{4}$') then 'Invalid Date'
    21         else dt
    22         end as dt
    23  from dt left outer join
    24               cal on (to_number(regexp_substr(dt,'[0-9]+')) between 1 and cal.dy
    25                   and to_number(regexp_substr(dt,'[0-9]+',1,2)) = cal.mn
    26                   and floor(to_number(regexp_substr(dt,'[0-9]+',1,3))/100) = cal.cen
    27*                  and to_number(substr(regexp_substr(dt,'[0-9]+',1,3),-2)) = cal.yr)
    SQL> /
    Enter value for date_dd_mm_yyyy: a1/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select 'a1/02/2008' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 01/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '01/02/2008' as dt from dual)
    DT
    01/02/2008
    SQL> /
    Enter value for date_dd_mm_yyyy: 29/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '29/02/2008' as dt from dual)
    DT
    29/02/2008
    SQL> /
    Enter value for date_dd_mm_yyyy: 30/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '30/02/2008' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 29/02/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '29/02/2009' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 28/02/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '28/02/2009' as dt from dual)
    DT
    28/02/2009
    SQL> /
    Enter value for date_dd_mm_yyyy: 0a/01/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '0a/01/2009' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 00/01/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '00/01/2009' as dt from dual)
    DT
    Invalid Date
    SQL>

  • How can i read the data fromtext fieldsin the form of bytes??

    Hi friends,
    How can i read the data fromtext fieldsin the form of byte string while using Socket connection.
    I have two text fields. i need to send the data from the textfeilds to the server using a byte string.
    Can anyboday help me???
    KK

    Does <cfdbinfo> work for Access DBs?
    You might be better off asking this on a MS Access forum.  It's more of an Access issue than a CF one.
    Adam

  • How can i save the data in a jpanel form to a .txt document

    how can i save the data in a jpanel form to a text file using parse function,this should happen when i click a save button .
    please help me..

    each time when i fill the form and click save button ,all the data in the form should be written to a text file and each time when i repeat it should append to the old data in the text file.the elements in the form should be seperated by pipe delimeter.
    thanks for your patience..

  • How can we transfer the date field in to the PO in R/3 from SRM

    Hi,
    We are using classic scenario with SRM release 5.50 and when we create SC using service option we can maintain the delivery date with start and end date in SC. In R/3 ECC 5.0 when the SC is converted as PO the end date is not reflected as we are using the copy of the standard PO document type NB and its taking the start date as the delivery date. How can i get the start and end date reflected to the PO from the SC in srm, do i need to add any customized field in the PO.
    Please suggest.
    Regards
    GGL.

    Hello,
    Did you find an answer to your question?  If so, can you please let me know.
    Thanks,
    Mark

  • How can I populate a date field when document is signed?

    I have 4 digital signature fields in a PDF form.  Next to each signature field is a date field (m/d/yyyy format).  I would like it so when the user signs the signature box that the date field next to it populates with todays date, then changes to read only (so it cannot be altered).
    In Adobe Acrobat Pro 9 I have this form and it has the following fields
    Signature1
    Signature2
    Signature3
    Signature4
    DateField1
    DateField2
    DateField3
    DateField4
    The Signature fields trigger a Topaz.GemSignPlus driver where the end user will be signing on an electronic signature pad.
    How can I use Javascript to detect when one of those Signature fields is populated and then fill in the date to the approrpiate date field?  I tried creating boolean variables initialized as false for each sig field.  Then when the signature is done I try to change it to true, but for whatever reason my javascript detecting the value doesn't do anything.
    I've searched the net endlessly for this solution.  I can't believe I'm having such a hard time finding an answer.  I mean how many places do you go where they ask you to "Sign and date here".  Every signature based document I've ever seen also requires a date.
    Anyway here's what I have.  In Document JavaScript functions I have a script name called populate date:
    function populatedate()
    var bSignature1 = new Boolean();
    var bSignature2 = new Boolean();
    var bSignature3 = new Boolean();
    var bSignature4 = new Boolean();
    if (bSignature1) {
        DateField1.value = util.printd ("m/d/yyyy", new Date());
    if (bSignature2) {
        DateField2.value = util.printd ("m/d/yyyy", new Date());
    if (bSignature3) {
        DateField3.value = util.printd ("m/d/yyyy", new Date());
    if (bSignature4) {
        DateField4.value = util.printd ("m/d/yyyy", new Date());
    In each signature field I have under the Signed tab "This script executes when field is signed:
    var bSignature1 = new Boolean(true);
    I'm trying to change it to true see.  My thinking is if its true than DateField1.value should print the m/d/yyyy in it from the built in Date() function.
    But maybe I am not getting this context correct.  I am new to Javascript in Adobe.

    It's quite a round-about script... Why not simply use the signature signing script to set the value of the date field? The correct syntax for that is:
    this.getField("DateField1").value = util.printd ("m/d/yyyy", new Date());

  • How can I set the date field to auto populate the current date?

    I have many forms to create where the current date dictates a specific change in options or conditions for the form filler to follow. I cannot see any way to handle that issue. Is it possible to simply set the current date as a default?
    jcytrny

    Sorry, we currently do not support having today's date show up in a date field by default
    Randy

  • How can we make disable a Field of a FORM at run-time?

    Hi to everybody,
    I want to know that how can we make a filed DISABLE at runtime <whenever we run a FORM>.
    I know about SET-ITEM-INSTANCE-PROPERTY but don't know how to use it,
    please make it clear.
    I will be gratefull to all of you
    Thanking you in advance.

    There's no property values for enabled or disabled in SET_ITEM_INSTANCE_PROPERTY.
    Instead what you can do is set INSERT_ALLOWED, UPDATE_ALLOWED and NAVIGABLE to FALSE which basically what a disabled item behaves like.
    Regards,
    Tony

  • How can I change Posting Date on Sales Invoice form in UI?

    Hello,
    I cannot change the Posting Date on the Sales Invoice form in UI.
    The new date is earlier than the system date, but when I type it on the field on the form, it's not problem!
    I've tried to use the following code in vb.NET:
    SBO_Application.Forms.Item(pVal.FormUID).Items.Item("10").Specific.value = DocDueDate.ToString("yyyyMMdd")
    But I've got an exception: <i>Form - Bad value</i>
    Next step I tried this, but I've got a same message:
    SBO_Application.Forms.Item(pVal.FormUID).Items.Item("10").Click(SAPbouiCOM.BoCellClickType.ct_Regular)
    SBO_Application.SendKeys(DocDueDate.ToString("yyyy.MM.dd"))
    Any idea?
    THX,
    Csaba

    Hi Csaba!
    please, make sure that you've handled Sales Invoice form - just show the message:
    MessageBox.Show(pVal.FormUID)
    edDate = SBO_Application.Forms.Item(pVal.FormUID).Items.Item("10").Specific
    edDate.value = DocDueDate.ToString("yyyyMMdd")
    This has to show you 133. If not then put the IF-statement to check what form you are handling before you try to get the item's handler

  • How can i validate the data in the control file?

    Consider that the SQLLoader reads the Input data File from the path and it loads the data into the tables based up on the descrition specified in the control File.
    First, the table to be filled is created:
    create table sql_loader_1 ( load_time date, field_1 Numeric, field_2 varchar2(10)
    Sample Control File :
    load_1.ctl
    load data
    infile 'load_1.dat' "str '\r\n'"
    insert into table sql_loader_1
    load_time sysdate,
    field_2 position( 1:10),
    field_1 position(11:20)
    Note that the positions 11 through 20 are loaded into field_1 and positions 1 through 10 into field_2. The field load_time is filled with the current time (sysdate) of the load.
    Here's the data. The name of the file (load_1.dat) had been specified with the infile statement in the control file.
    load_1.dat
    0123456789abcdefghij
    foo bar
    here comes a very long line
    and the next is
    short
    Here i want to validate the field_1 (Numeric Datatype) since the data file contains the character value (i.e)abcdefghij

    Good question for this forum:
    Export/Import/SQL Loader & External Tables
    Werner

  • How can we hide Additional data fields - Contract Elements - Belgium

    Hi ,
    I want to Hide additional data fileds( IT0109) which are contry specific for belgium  in contract elements Infotype ( IT0016)
    I am not able to find these fileds in module pool MP001600. Please help me in this regard.
    Thanks in advance.

    Dear,
    Please check in T588M table
    Module Pool          MP001600            Variable key    12
    Standard screen      2000                Feature
    Alternative screen   2012
    There you should have Contract Type field.
    Best Regards,
    Deepak..

  • How can I validate a UDF field in SP_PostTransactionNotification

    Dear Experts,
    For some reasons, I have a UDF "U_DocNum", and I will like to run a duplicate validation on this document number field everytime before the marketing document is posted.
    Can anyone provide me with the codes I should put in the SP_PostTransactionNotification for this validation (I hope im correct of this SP name).
    Much Thanks in Advance for your help!
    Warmest Regards,
    Chinho

    For invoice you can use this
    IF @transaction_type IN ('A','U') AND @object_type = '13' 
    BEGIN
    if exists
    (Select CardCode from [dbo].[OINV] T0
        Where T0.DocEntry!=@list_of_cols_val_tab_del
          and T0.U_DocNum=
      (select U_DocNum From OINV
        Where DocEntry=@list_of_cols_val_tab_del) )
    begin
         SELECT @error = 1, @error_message = 'Duplicate value !'
    end
    END
    For every other transaction type you can insert a similar code
    (Insert this in your  SBO_SP_TransactionNotification stored procedure after the line
    --     ADD     YOUR     CODE     HERE )

  • How can i validate  the field directline under personal information of ESS?

    Hi all,
    How can i validate the field directline under personal information--> communication data  of ESS?The thing is we don't have NWDI setup in our organization.Is there any possibility of doing it under SPRO trn.
    Thanks and Regards,
    sam

    Hi,
    This is probably a wrong forum that you have posted your question to.
    Regards,
    Siddhesh

  • How can i validate(compare) two date type attribute in EO.

    Hi All,
    jdev version 11.1.2.1.0
    i have created one EO where two date type attribute ToDate and FromDate now i want to add validation rule.
    which validate that difference b/w ToDate and FromDate not more than 3 month.
    How can i validate this?

    You can create script expression
    Something like
    if((toDate.getTime()-fromDate.getTime())/(1000 * 60 * 60 * 24)>30)
      return true;
    else
      return false;-Arun
    P.S : Above example calculates based on number of Days (30). If you want 3 months, you need to put a logic - Simply 90 days? What about the months with 31 days and 28/29 days? etc.

  • How can i validate input number into a Field of  type char in oracle form?

    hi.....
    can any one help me.....please...!!!?!!
    How can i validate input number into a Field of type char in oracle form?

    i have tried doing that, but still the field except numbersthere was an error in that code. it should have been
    var_num:=to_number(var_char);however, it appears that you want the entry NOT to be a number. if this is the case then try
    begin
      if to_number(:block.item) = 0 then null; end if;
      message('The entry cannot be numeric');
      raise form_trigger_failure
    exception
      when value_error then
       /* this is where you put the code you want to be run when the
          entry is non-numeric */
    end;

Maybe you are looking for

  • Input Field of Type Time Unable to Keep Input Value

    Hi, I am facing the following problem: I am using an input field of type time that initially its value comes from a BAPI call. I want though to be able to change its value and use the same field as import parameter for another BAPI. The value of the

  • Need Urgent help in downloading the pkg from Sunfreeware

    Hi all, I am trying to down load few pkgs from Sunfreeware. On the site I see 2 sets of pkgs for the same pkg. one which ends with local.gz & the other one with .gz ( which is a source code) Which one do I download & how do I add it using the pkgadd

  • Column data formatting in OBIEE ANSWERS

    Hi, I have a requirement of putting '-' whenever column value is NULL. I am doing this ANSWERS. I am doing this by using the below. IFNULL(CAST("COLUMN NAME" AS CHAR),'-'). It is correctly replacing by '-' whenever data is NULL but it is also overrid

  • I get an error when updating iPod...

    I've done everything the support tutorial has told me to do and nothing has worked. It used to be a (-36) error but now it just plain says the disk can't be read from or written. I'm tired and want my music, I hope I can fix this soon since I have a

  • Can't arrange movie files in itunes?

    In itunes, whenever i click on the "movie" file under my iPod Touch's name, the list of all the movies i have in my ipod show up. However, whenever i want to move the files around/organize them, it won't let me move them. It's like the movie files ar