Forum Discussion

Fischerd's avatar
Fischerd
New Contributor
8 years ago

Date Validation using Expression Library

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:

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:

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

  • tstack's avatar
    tstack
    Former Employee

    Unfortunately, regular expression objects do not have a test() method at this time. You’ll need to use one of the methods on strings, like match().

    Also, if you were not aware, there is a Data Validator snap that can check strings against patterns.

    • Ksivagurunathan's avatar
      Ksivagurunathan
      Contributor

      Is there a way to do validation dynamically. I mean I can provide list of fields and list of validation needs to be performed . Is it possible to perform validation based on the input. rater than hardcoding the condition for each and every filed. Eg - I have two files. One file with 10 fields and another 20 fields and I need to validate the not null and length constraints against each of the filed in two file. I want to achieve this in a pipeline . In future if new column added to the same file, I shouldn’t make changes to pipelines , rather than just add the column and condition in properties file or store the info in a table, the pipeline should dynamically validate the new column. Is it possible to do this in snaplogic ?

  • Majid's avatar
    Majid
    New Contributor III

    @Ksivagurunathan Did you get any work around for the dynamic validation pipeline. I am trying to build something similar and would like to know if designed any solution .

    • Ksivagurunathan's avatar
      Ksivagurunathan
      Contributor

      it wasn’t a straight forward solution. we developed a custom javascript function that read input data,rules and validate them and add a json output for every row in case of any error. Javascript function is generic for all data type, nullable and not nullable. Input rules and input rows could change

      • raja's avatar
        raja
        New Contributor

        @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's avatar
    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