Best Practices

 View Only
  • 1.  Regex, Regex and more Regex

    Posted 08-26-2021 11:23
    Regex is a short form for Regular Expressions (more info: Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns) They are used to "match" on a number of different patterns that might be input into a form. In ProntoForms there are 2 places where Regex can and should be used when possible. We will cover both of those applications and a few tips and tricks for building out those Regular Expressions in this article.

    1.  Answer Validation - see Custom Validation (Data Type: Free Text) Using Regex as a custom validation method allows you to be 100% certain that the information that is being input into the form is exactly what you are expecting. If you want to make sure that the number they input starts with a 2, regex can do that. Make sure that there are 5 characters (no more - no less), regex can do that. We can not put examples of all the different ways to use Regex to perform this validation but there is tons of information online about it.
    2. Data Destination Filtering - see Custom Filter Rules (Applying Filtering to Data Destinations) We can also use Regex when applying a filter to a data destination to determine if the destination will get triggered or not. All the same rules apply here as they do in the Custom Validation.
    Some things to note. When dealing with Regex, you will almost always want the start of the expression to be a ^ (which indicates the beginning of a string) and end your expression with a $ (meaning the end of the string). From there, you can use a tool like RegExr: Learn, Build, & Test RegEx to figure out if the expression that was built is going to match the strings that you put in the form. When you are first trying to come up with your expression - I would always suggest a quick google search because with the complexity of Regex expressions, no doubt someone has the expression figured out that you need.

    ------------------------------
    Ian Chamberlain
    Implementation Specialist
    ProntoForms
    ------------------------------


  • 2.  RE: Regex, Regex and more Regex

    Adopter
    Posted 08-30-2021 13:48
    I have dealt with Regex before in other applications (primarily Python) but haven't found a use for it yet in Pronto.

    ------------------------------
    Scott Gilleland
    Senior Field Service Engineer
    Messer Cutting Systems
    ------------------------------



  • 3.  RE: Regex, Regex and more Regex

    Posted 08-30-2021 16:17

    The most common usage I see in forms is restricting the number of characters that can be input into a text field. Can be important when dealing with integrations into other systems. Some data destinations also have limits of how many characters can be sent over.

    Like Microsoft Lists, it has a 255 character limit on its "Single line of text" and passing anything more will result in an error so using Regex to limit the number of characters typed in can be useful. 

    If ever you do find that spot where it will come in handy, report back how you used it! I am always curious about more usages. 



    ------------------------------
    Ian Chamberlain
    Implementation Specialist
    ProntoForms
    ------------------------------



  • 4.  RE: Regex, Regex and more Regex

    Posted 08-31-2021 10:01
    Edited by Scott Daly 08-31-2021 10:01
    One other common area we see regex being used is for things like serial/model number input validation.

    So if we know that a piece of equipment will have a serial number that should be 2 characters followed by a hyphen and 5 numbers (ex. SN-12345), we can easily enforce this through regex. In the example above the following regular expression would work:

    ^[A-Za-z]{2}-[0-9]{5}$


    ------------------------------
    Scott Daly
    Senior Manager, Implementation Services
    ProntoForms
    ------------------------------



Reminder: Content posted to our Community is public content.  Please be careful not to post Intellectual Property that you do not have permission sharing.  For more information please refer to our Terms Of Use