We have users that want to enter date as mmddyyyy without slashes. They don'

We have users that want to enter date as mmddyyyy without slashes. They don't want to use the DATE type, so this will be a string/text. Also they would like to see this date displayed after they enter is with the slashes, so mm/dd/yyyy. Does anyone has a example, I guess javascript to validate what user entered is a valid date? fyi we noticed the Appian Date type does not validate that the date is valid if you manually enter the date, for example if you enter 13/99/2013 and tab away it does not tell you its invalid, but instead converts to some kind of date. Thanks!...

OriginalPostID-128041

OriginalPostID-128041

  Discussion posts and replies are publicly visible

Parents
  • yes you are correct. As I mentioned above the todate() does not work. Below is my script that validates the date correctly. It me be entererd in mm/dd/yyyy format first. Hope this helps you.
    var tstdate = FormAPI.getValue("text11").id.substring(0);
    var tstdate = tstdate.split("/").join("");
    tstdate = tstdate.substring(0,2)+"/"+tstdate.substring(2,4)+"/"+tstdate.substring(4);
    var splitDate = tstdate.split("/");
    var monthfield=splitDate[0];
    var dayfield=splitDate[1];
    var yearfield=splitDate[2];
    var dayobj = new Date(yearfield, monthfield-1, dayfield);
    if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
    {
    window.FormAPI.setValue("text11","");
    alert("Invalid Day, Month, or Year range detected. Please correct.");
    }
    else
    {
    window.FormAPI.setValue("text11",tstdate);
    }
Reply
  • yes you are correct. As I mentioned above the todate() does not work. Below is my script that validates the date correctly. It me be entererd in mm/dd/yyyy format first. Hope this helps you.
    var tstdate = FormAPI.getValue("text11").id.substring(0);
    var tstdate = tstdate.split("/").join("");
    tstdate = tstdate.substring(0,2)+"/"+tstdate.substring(2,4)+"/"+tstdate.substring(4);
    var splitDate = tstdate.split("/");
    var monthfield=splitDate[0];
    var dayfield=splitDate[1];
    var yearfield=splitDate[2];
    var dayobj = new Date(yearfield, monthfield-1, dayfield);
    if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
    {
    window.FormAPI.setValue("text11","");
    alert("Invalid Day, Month, or Year range detected. Please correct.");
    }
    else
    {
    window.FormAPI.setValue("text11",tstdate);
    }
Children
No Data