Fredrik Norling blogged yesterday about using Regular Expressions to validate in XPages (but also traditional Domino web development). There is one option for validating using regular expressions that Fredrik didn’t mention, and it’s well worth covering. Because although you can find a lot of regular expressions on the web, writing your own or modifying regular expressions can be challenging. And testing the regular expressions can be a slow and boring process. Wouldn’t it be great if you had a wizard to build them in Domino Designer? Wouldn’t it be great if you could test them from within Domino Designer?
Well, actually you can, thanks to those nice developers at IBM.
If you want to validate and throw errors client-side, you might want to use the Dojo Validation Text Box. If not, it’s still worth dropping a Dojo Validation Text Box on your XPage, just to be able to play about with and test your regular expressions in Designer. The Dojo Validation Text Box has a property called regExp. You can manually type the regular expression in, as with the validators. But things get really interesting when you launch the external property editor.
That first tab allows you to build up your regular expressions. You can select from predefined tokens such as “Any character”, “Alphanumeric character”, “Lower case”, then define the number of occurrences. The Add button allows you to build up a regular expression.
And if you find a regular expression online that you think is what you need, you can just type it into the “Current regular expression” box.
Click Next> and you can test the regular expression.
Enter sample text and while it fails to match your regular expression, you see the error message in the title bar. Once it matches, the warning message changes to an information message telling you “The text matches the regular expression”.
It’s almost enough to make you want to prefer regular expressions for validating text fields.