Cognito-forms – Regular Expressions

cognito-formsregex

I am experimenting with Cognito Forms' new feature of text input validation by use of Custom Regular Expressions. I was asked by one of our departments to make the name fields autocorrect so as to make the first character of each uppercase if the user or person filling out the form accidentally leaves it lowercase. I got the regular expression that I want to use:

Image Capture

However, every time I click SAVE the Reformat Expression box becomes blank, and the Custom Regular Expression doesn't work as expected.

I used RegEx to test my regular expression format to make sure it's correct, and I even used the custom error message on the Cognito Forms app to make sure the form is reading the regular expression correctly. But for whatever reason, it won't accept the Reformat Expression I enter.

Does anyone have any idea or have any more experience with regular expressions used in Cognito Forms?

Best Answer

Cognito Forms supports any regular expression that will work in a web browser using JavaScript, so this is not specific to Cognito Forms.

As noted in our help documentation, there are a number of good websites for learning how to write and test regular expressions. If you are still stumped, try posting on Stack Overflow, as this is really a programming question and more appropriate for those forums.

In this specific case, the issue is with your reformat expression, where you are trying to include the first group ($1). However, since there are no () in your regular expression, there are no groups. To include the entire value, use $& instead.