Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Date Validation
dlukezic
Hi everyone! I have set up a custom field for my users to input when submit files to a workflow. The field takes in a date and time with the format:
yyyy-mm-dd hh:mm
Can anyone help me to create the right valid_input value for this to ensure that the correct date/time format is entered and that the date is a valid date (eg. Feb. 30th is invalid)? I am new to both workflow and regular expressions.
I am currently using the following regular expression on my DCTs for just the date portion:
((19|20)[0-9][0-9]-(((01|03|05|07|08|10|12)-((0[1-9])|([12][0-9])|(3[01])))|((04|06|09|11)-((0[1-9])|([12][0-9])|(30)))|(02-((0[1-9])|(1[0-9])|(2[0-8])))))|((19|20)(((04|08))|((2|4|6|8)(0|4|8))|((1|3|5|7|9)(2|6)))-02-29)
But when I try to use this in my workflow, I get an internal server error.
Please help!
Thanks in advance!
Doreen
Find more posts tagged with
Comments
Migrateduser
Can you use FormAPI? Doing this with a regex is a little clumsy, and if you find a problem with the regex you have to update all DCTs. It's pretty easy in FormAPI.
dlukezic
Thanks for the quick response. Because I am trying to do this in a workflow, I cannot use FormAPI or validation_regex. I have to use valid_input under the TAG_INFO directive.
Doreen
Migrateduser
Then you definitely don't have to do it with a regex. The value of valid_input can be a subroutine which can be as complicated as you need it to be. You can see serial_approval.wft in the examples folder for several good examples of this.
ySeriesAxisScale.JPG
dlukezic
Thank you. I have checked out the sub-routines. I think that I am looking for something simpler though. I should be able to do this just with a regular expression, but the regular expression that I am using (see below) is giving me an Internal Server Error.
valid_input => '((19|20)[0-9][0-9]-(((01|03|05|07|08|10|12)-((0[1-9])|([12][0-9])|(3[01])))|((04|06|09|11)-((0[1-9])|([12][0-9])|(30)))|(02-((0[1-9])|(1[0-9])|(2[0-8])))))|((19|20)(((04|08))|((2|4|6|8)(0|4|8))|((1|3|5|7|9)(2|6)))-02-29)',
If anyone can help me to adjust this regular expression (works on my DCT, but does not work on my workflow where I need it), that would be great.
Thanks in advance!
Doreen
Migrateduser
The point we're trying to make is that doing it with a regex isn't simpler. After all, you've managed to create the ugliest regex I have ever seen, which is pretty amazing considering that you didn't use any metacharacters or the /e modifier. I think it also has broken logic in that it looks like it would accept 1900-02-29 which is not a valid date.
Anyway - your major problem is probably that you omitted the matching operator and just have a bunch of characters in a string that doesn't make a valid perl expression.
Try this:
valid_input => 'm/((19|20)[0-9][0-9]-(((01|03|05|07|08|10|12)-((0[1-9])|([12][0-9])|(3[01])))|((04|06|09|11)-((0[1-9])|([12][0-9])|(30)))|(02-((0[1-9])|(1[0-9])|(2[0-8])))))|((19|20)(((04|08))|((2|4|6|8)(0|4|8))|((1|3|5|7|9)(2|6)))-02-29)/',
add_rptparam.jpg
Migrateduser
I think there are at least two uglier regexes, email and url (in some ways the same thing), and I've never seen either work 100% (or date for that matter). I think it's better to set the regex to something like "URL" in your code and use JavaScript translate this to the real regex, or even better, parse with logic. Use appropriate tools for the task...
dlukezic
Thanks very much for the response! The regular expression worked very well! In fact, 1900-02-29 was found to be an invalid date.
Thanks again!
Doreen