You are viewing limited content. For full access, please sign in.

Question

Question

Pre & Post Validation not matching

asked on September 4, 2018

We have the following regex set on a field: ^[0-9a-zA-Z]{4,20}$

If user types some text and then puts in a bunch of spaces the pre validation does not show the error. Though if they put a few char, space, more char, the pre validation does work.

No Error: "value          "

Error: "value value value"

But when the form is submitted with spaces at the end the backend validation does show that value doesn't match regex.

Has anyone else had this happen/know how to fix it? Or is this a bug?

1 0

Replies

replied on September 6, 2024

I can confirm that I was able to reproduce this issue in a Forms process on version 10.4.1.172, and that it did not happen in version 11, so this must have been fixed at some point.

 

But just to clarify in case it helps anyone:

Problem: A field value fulfills its constraint other than the fact that it has spaces at the beginning and/or end that are not part of the constraint. These extra spaces do not trigger the error on the form of an invalid value, but throws an error after submitting the form.

Solution: When the submit button is pressed, trim the value. Ex:

$(document).ready(function() {
  $('.Submit').click(function(){
    let trimmed = $("#q1 input").val();
	$("#q1 input").val(trimmed.trim());
  });
});

In version 11, these extra spaces are trimmed automatically. Not sure exactly which version number this was fixed in.

1 0
replied on September 5, 2018

Just so I'm clear, what is the intended validation?

0 0
replied on September 5, 2018

Either that the form doesn't allow extra spaces at the end (auto-trim feature I'm assuming) or that the backend validation trim's the extra spaces as well. That way the user doesn't submit a form that the backend is then going to say didn't validate. The user should know after going to the next field, before ever clicking on Submit, that what they entered in the field was not correct.

0 0
replied on September 6, 2018 Show version history

You are very close. I would just add a "negative lookbehind" to your regular expression. The negative lookbehind specifies that the entire string only matches if the regex inside of it does not match.

^[0-9a-zA-Z]{4,20}(?<! +)$



0 0
replied on September 6, 2018

Hi Devin, I think you have the right answer but the regular expression field isn't accepting that. I believe it doesn't like the "<" character. I found a couple other posts that mention backend validation error's and that it's a bug. So for now we'll turn off the backend validation. Hopefully LF will have this fixed in the next update.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.