In one of our Forms processes we have a multiline field where users paste text into it. The text usually has multiple lines, and each line needs to be in a specific format to be valid. Rather than have Workflow check it after the form is submitted, I am wondering if there might be a way for a formula to be able to check the formatting of each line that is entered?
Question
Question
Can a Formula be used to check line formatting in multiline field?
Replies
I suppose it would depend on the evaluation. The SPLIT function could be used to break the text up based on line breaks, but I don't know if that would really lead to anything useful for this.
Since multi line fields don't have regex, I'd say your best option is a custom validator.
window.Parsley.addValidator('multilineformat', { validateString: function(value, requirement, field) { var valid = true; // default validation output // loop values split on line break // may need adjustment for other possibilities like carriage returns $.each(value.split('\n'),function(index, value){ // add your evaluation here and return false if not valid if (value == 'test') { valid = false; // set validation to false if any line fails } }); return valid; }, messages: { en: 'Invalid format.', // whatever error message you want } }); // assign validator to field $('.myMultiLine textarea').attr('data-parsley-multilineformat','');
Thanks Jason. I'll take a look at your script.
To evaluate the value based on a regular expression would one just put the expression in or is there something else that needs to be added for it to work correctly?
You would add a regex comparison in and return false if it fails the check.
For example,
if (!string.match(regex)) return false;
or using a RegEx object
if (!regex.test(value)) return false;
Something along those lines. to replace if (value=='test')
I've been playing with this today and haven't been able to get it to work yet. In the Dev Tools Console it says "Uncaught SyntaxError: Invalid or unexpected token". The issue appears to be when I enter the regex.
What does your code look like with the regex? The specific code/syntax would depend on whether you're using .match() or .test()
Well, I removed it at some point, so I don't have it anymore. As an example of what we're trying to do, we have a Forms process that has a multiline field. The end users are supposed to enter GL Codes on each line in a specific format (this is part of a larger process and there is a reason they enter it this way). The data is eventually applied to a repository entry's metadata. For this example, there is a constraint on the GL Entry field in the repository of \d+-[\dxX]+-\d+-\d+:\-?\d+\.?\d?\d?. Using what you posted, how would you add that so Forms could check each line adheres to that format for the specific field?
Did you have any luck on this Jason?
I haven't really messed with this too much, but the code should work. From the error message you described it sounded like it just needed a change in how the RegEx syntax was added to the code.