cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Date Validation using Expression Library

Fischerd
New Contributor

Hi,

Iโ€™m developing a pipeline that uses date input parameters. I was looking to use an expression library to validate the date format by matching a regex pattern.

For example, /^([1-9]|0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/(19\d\d|20\d\d)$/.test(โ€œ05/09/2018โ€) should return โ€˜trueโ€™
Below are the pipeline properties where I am importing the expression library:
image

Here are the contents of the .expr file:
{
sd_valid: x => (/^([1-9]|0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/(19\d\d|20\d\d)$/.test(x))
}

Here is the mapper I am trying to you to call the validation:
image

I am receiving the following error when trying to validate the pipeline in this case:

โ€œFailure: RegExp type does not have a method named: test. Perhaps you meant: No Regex Methods, Reason: โ€˜testโ€™ was not found while evaluating the sub-expression โ€˜/^([1-9]|0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])\/(19\d\d|20\d\d)$/.test(x)โ€™, Resolution: You can check for the existence of a field with the โ€˜inโ€™ operator (e.g. โ€˜abcโ€™ in $obj)โ€

Has anyone else seen this problem and found a solution? Or know a better way to accomplish what Iโ€™m trying to do here?

Thank you in advance
Dan

7 REPLIES 7

@Ksivagurunathan we have a similar requirement. Need a generic data validation solution. Appreciate if you Can you help me with the js function. Thanks.

amar
New Contributor II

I didnโ€™t see any solution on it. Can someone please help out on validating date parameter to certain format. In my example, i have parameter $start_date where i need validate whether it matches โ€˜MM/DD/YYYYโ€™ or not. Iam looking some kind of javascript expression that routes to error if format fails.

Thanks

skatpally
Former Employee

Data Validator Snap can do the trick. Attached a sample Pipeline for reference. Delete_2020_12_01.slp (3.8 KB)