IBM Forms: Fields with no spaces
Sometimes you need to get the user to enter a string value with no spaces. Regexes to the rescue! Here's a simple field that accepts any string, as long as it doesn't have spaces.
XML:
<field sid="FIELD4"> | |
<xforms:input ref="@id"> | |
<xforms:label></xforms:label> | |
</xforms:input> | |
<itemlocation> | |
<width>111</width> | |
</itemlocation> | |
<scrollhoriz>wordwrap</scrollhoriz> | |
<format> | |
<datatype>string</datatype> | |
<constraints> | |
<patterns> | |
<pattern>\S*</pattern> | |
</patterns> | |
</constraints> | |
</format> | |
</field> |
The "\S*" pattern is what enforces the no-spaces rule. Note that tab characters are also filtered out. This regex says:
\S - any character but a white space character
* - repeat 0 or more times
Note that the default error message is a bit cryptic, so either override the help message or ensure the label for the field clearly indicates not to use spaces!
You can use this in conjunction with a length restriction to limit the input to a certain size (or just use a more sophisticated regex!)
My personal favourite Regex reference is actually the javadoc for the Pattern class. Obviously, for forms you don't need to concern yourself with the java api, but the regex summary at the top of this page is very nicely laid out in my opinion.