Get the Date from user on button click and Validate the date entered
Problem:
There was a scenario, where I had to Pass the effective date of an Insurance policy to the workflow for further processing whenever the user clicks a buttonSolution:
I used the browser script of that applet and invoked the following script:if(name == "<button method>")
{
var person = prompt("Please enter the effective date","MM/DD/YYYY");
var datePat = /^(\d{2,2})(\/)(\d{2,2})\2(\d{4}|\d{4})$/;
var matchArray = person.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date must be in MM/DD/YYYY format");
}
else{
//Month Check
var month = matchArray[1]; // parse date into variables
var day = matchArray[3];
var year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12");
}
//Day Check
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31");
}
//Months with 31 days
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!");
}
}
return("CancelOperation");
}
Comments
Post a Comment