Data Validator - allow null values

I’m trying to use the Data Validator snap to validate birthdays in a file.

The birthday (DOB) field is optional - it can be null, but if there is a date it needs to be in the proper format.

I have this regex in my Data Validator, but it is catching null values as well. Is there a good way around this?


The Data Validator Snap will fail if the incoming data does not match the defined constraints with the regex.

You can try with:

If DOB field is optional, and is expected to be null, then you can check if that field(“DOB”) is null/or not right before the data validator snap.

If it is null, then process it further(to the snaps after the Data Validator) without calling the Data Validator Snap, containing the regex.

If it is not null, then go through the Data Validator Snap and perform validations.

Also, you can achieve the desired format of the date field by using the proposed Date Functions.

Hope this helps.

Spiro Taleski

1 Like

Thank you @Spiro_Taleski. That would work, but I also need to run the Data Validator snap on other fields as well.

I have managed to work around the issue for now by using a Conditional snap before the Data Validator that checks for null values in the DOB field and transforms them to an empty string ''. Then use the this regex that matches either an empty string or the date: ^|\d{1,2}/\d{1,2}/\d{4}$

1 Like

There is supposed to be a dollar sign $ after the caret ^ symbol in the regex above. Somehow it gets filtered out of the post.

While the Conditional snap may work in this case, I would also recommend looking at the Mapper snap with the following $.get expression as an alternative for the same:


(Note: Pass through is checked so that the only fields you need to concern with are those you need to run through the validator as a string.)

I don’t know that it’s a huge benefit, but it seems cleaner/easier to me and it allows for additional transformations/mappings on other fields in the same snap.

Helpful tip: In this forum, you can use the image icon to encapsulate code to preserve formatting ^$|\d{1,2}/\d{1,2}/\d{4}$

1 Like