Skip to main content
Solved

Regex to prevent the use of newlines in a text field


Forum|alt.badge.img+4

I’m no regex expert but I’ve managed to fudge together what I thought would be a functional check for whether a form filler is trying to use new line characters in text fields. My regex is:

(?<=[^\r\n])\R(?=[^\r\n])

It looks like it should work:

 

But when I implemented the regex in my web form entering anything in the field results in the input failing the validation check:

 

What am I missing? Do web forms use new line characters as part of the field? Why would a single word with no spaces or anything match my pattern?

Best answer by gulf5724

Alejandro.Ramos wrote:

Hi @gulf5724,

 

Thank you for sharing your experience.

Are you selecting “Long Text”, as part of your text box settings?

Best regards,   

 

Alejandro R. | Docusign Community Moderator   

"Select as Best" below if you find the answer a valid solution to your issue!   

 

 

Yes.

mrave wrote:

@gulf5724

Can you explain the use case and why you want to filter out the new line breaks?

I came across the issue with new line breaks working with SharePoint, when the text field is defined as multiple lines of text. This can result in issues when you pass the values via API to Docusign. 

Another use case I saw before is when people copy and paste data from an Excel file, where the data fields included line breaks, which caused some trouble with document generation and workflow processes in CLM.

Its because employees entering line breaks into the web form fields allowed text to escape the desired bounds of the defined area on the completed PDF agreement.

 

I did not figure out why my regex didn’t work, but I was able to accomplish the same end goal by simply changing the problematic fields to short text. This prevents users from entering new lines.

View Original
Is this content helpful?

8 replies

JohnSantos
Valued Contributor
Forum|alt.badge.img+18
  • Valued Contributor
  • 959 replies
  • July 31, 2024

@gulf5724 

If your goal is to simply detect the presence of newline characters in any text input, a simpler approach might be more effective: [\r\n]

This pattern will match any occurrence of \r (carriage return) or \n (newline) in the input. This is generally sufficient for detecting newline characters in text fields.


Forum|alt.badge.img+4
  • Author
  • Conversation Starter
  • 11 replies
  • July 31, 2024
JohnSantos wrote:

@gulf5724

If your goal is to simply detect the presence of newline characters in any text input, a simpler approach might be more effective: [\r\n]

This pattern will match any occurrence of \r (carriage return) or \n (newline) in the input. This is generally sufficient for detecting newline characters in text fields.

It still fails the validation check:

 

 


Forum|alt.badge.img+4
  • Author
  • Conversation Starter
  • 11 replies
  • August 5, 2024

Anybody else have any ideas? It seems like it should be working….


Forum|alt.badge.img+15
  • Community Moderator
  • 2070 replies
  • August 22, 2024

Hi @gulf5724,

 

Thank you for sharing your experience.

Are you selecting “Long Text”, as part of your text box settings?

Best regards,   

 

Alejandro R. | Docusign Community Moderator   

"Select as Best" below if you find the answer a valid solution to your issue!   

 

 


Michael.Rave
Docusign Employee
Forum|alt.badge.img+14
  • Docusign Employee
  • 927 replies
  • August 22, 2024

@gulf5724 

Can you explain the use case and why you want to filter out the new line breaks?

I came across the issue with new line breaks working with SharePoint, when the text field is defined as multiple lines of text. This can result in issues when you pass the values via API to Docusign. 

Another use case I saw before is when people copy and paste data from an Excel file, where the data fields included line breaks, which caused some trouble with document generation and workflow processes in CLM.


Forum|alt.badge.img+4
  • Author
  • Conversation Starter
  • 11 replies
  • Answer
  • August 23, 2024
Alejandro.Ramos wrote:

Hi @gulf5724,

 

Thank you for sharing your experience.

Are you selecting “Long Text”, as part of your text box settings?

Best regards,   

 

Alejandro R. | Docusign Community Moderator   

"Select as Best" below if you find the answer a valid solution to your issue!   

 

 

Yes.

mrave wrote:

@gulf5724

Can you explain the use case and why you want to filter out the new line breaks?

I came across the issue with new line breaks working with SharePoint, when the text field is defined as multiple lines of text. This can result in issues when you pass the values via API to Docusign. 

Another use case I saw before is when people copy and paste data from an Excel file, where the data fields included line breaks, which caused some trouble with document generation and workflow processes in CLM.

Its because employees entering line breaks into the web form fields allowed text to escape the desired bounds of the defined area on the completed PDF agreement.

 

I did not figure out why my regex didn’t work, but I was able to accomplish the same end goal by simply changing the problematic fields to short text. This prevents users from entering new lines.


Forum|alt.badge.img+1
  • Newcomer
  • 4 replies
  • August 25, 2024

It sounds like you initially tried to use a regex pattern to prevent new line characters in a form field, but it didn’t work as expected. The issue might be that web forms often handle text differently, and your regex could be matching unintended cases.

If changing the field to "short text" worked for your use case by preventing new lines altogether, that's a practical solution. Sometimes, simpler fixes like adjusting the field type can be more effective than complex regex patterns, especially when dealing with web forms.

If you still need to use regex in the future, you might want to double-check how the text is being processed and whether there are any hidden characters or formatting that could affect the regex behavior.


Forum|alt.badge.img+4
  • Author
  • Conversation Starter
  • 11 replies
  • September 3, 2024
Saqs wrote:

It sounds like you initially tried to use a regex pattern to prevent new line characters in a form field, but it didn’t work as expected. The issue might be that web forms often handle text differently, and your regex could be matching unintended cases.

If changing the field to "short text" worked for your use case by preventing new lines altogether, that's a practical solution. Sometimes, simpler fixes like adjusting the field type can be more effective than complex regex patterns, especially when dealing with web forms.

If you still need to use regex in the future, you might want to double-check how the text is being processed and whether there are any hidden characters or formatting that could affect the regex behavior.

How would I double check how web forms process text? It would be helpful to know this for the future.