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

Question

Question

Regex with Apostrophes Failing

asked on June 20, 2018

Hi,

 

I have a form with an address field in which we are allowing alphabetical characters, accented characters, numbers, hyphens and apostrophes.

I have the following regular expression applied to the field.

 

^[A-ZÁÉÍÓÚáéíóúa-z0-9][A-ZÁÉÍÓÚáéíóú a-z0-9'\-]*[A-ZÁÉÍÓÚáéíóúa-z0-9]$

 


 

This seems to work correctly on the form itself but whenever I include an apostrophe in my data the submission fails with the error shown below. I could circumvent this issue by using custom javascript to validate but where possible I would like to make use of the backend validation. Does anyone have a suggestion on how to fix this? Is there any problems with my regex itself?

 

Atm I'm guessing it's something to do with string encoding or anti injection procedures on the backend.

 

0 0

Answer

SELECTED ANSWER
replied on June 26, 2018

Thanks for your input/suggestions on this Chris.

 

I opened a ticket and got a response from Laserfiche support. It is indeed a bug. The current suggested workaround is to turn off backen validation.

1 0

Replies

replied on June 21, 2018 Show version history

Looks like you are only allowing apostrophes in your second bracket. There are no apostrophes anywhere else in your regex. Is that correct? You could test it in a workflow activity in the Token Dialog option.

 

I am a little rusty but it looks like the following are allowed:

A-------0

^one character + any number of character including apostrophe + one character

B-1

^one character + any number of character including apostrophe + one character

Ckjdfldjfljdalfkjdalfkjdf--''''''1

^one character + any number of character including apostrophe + one character

 

Edit: I was looking at this again. Perhaps you want your code to be:

^[A-ZÁÉÍÓÚáéíóúa-z0-9]*[A-ZÁÉÍÓÚáéíóú a-z0-9'\-][A-ZÁÉÍÓÚáéíóúa-z0-9]*$

or

^[A-ZÁÉÍÓÚáéíóú a-z0-9'\-]* || [A-ZÁÉÍÓÚáéíóúa-z0-9]*['][A-ZÁÉÍÓÚáéíóúa-z0-9]*$

^the "||" represents OR. So this would be:

any number of characters (no spaces) OR  

any number of characters (no spaces)+'+any number of characters (no spaces)

 

Good luck!

1 0
replied on September 6, 2018

Will this be fixed in the next update or has a patch already been pushed?

1 0
replied on June 22, 2018

Thanks for your input Chris.

 

I tried out all of your suggested regular expressions and had the same problem with all of them. They validate fine on the form but if I submit and the data contains an apostrophe then it will give an error after submission.

For example the string "te'st" will not successfully submit for me using any of the regex listed in the thread so far even though it validates on the front end.

 

I also tried this on a new blank form with no CSS or custom Javascript.

0 0
replied on June 22, 2018 Show version history

I see. I recall something like this happening in Workflow in a past version.

A workaround could be to character swap. In other words, IF the string has an apostrophe, THEN swap it with an alternative character that is not in you character list such as "~". or even specific text like "[apost]", ect. Have the apostrophe swapped so it can go in. Then on the form use javascript to search for your special character and revert it back to an apostrophe. You might only need to do this when the form is user facing otherwise it could just stay an a converted character.

In other words, IF a variable contains "[apost]" THEN swap that character for an apostrophe. 

Personally, I would open a support ticket to Laserfiche through my VAR in case there is a bug in there. 

Good luck!

0 0
SELECTED ANSWER
replied on June 26, 2018

Thanks for your input/suggestions on this Chris.

 

I opened a ticket and got a response from Laserfiche support. It is indeed a bug. The current suggested workaround is to turn off backen validation.

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

Sign in to reply to this post.