Check the account field for valid input
Configure the new account field in Printgroove JT Web and Printgroove JT Suite to automatically validate the user's input. Thus only print jobs with valid accounts are submitted.
As we wrote in our last article about the new account field, you can choose between a pull-down-menu and a text box to display the field. For the pull-down-menu you define the selectable values beforehand by yourself, thus a validation of the input isn't necessary.
Validate the input by using regular expressions
But if you decide to use a text box, a validation of the input may be reasonable. The validation is done by the use of regular expressions, which you can use to check the composition of strings. You can add such a regular expression in the configuration of the account field. As a result all input of users is checked by using this expression.
Which regular expression you should use for validation depends on the format and composition of the accounts used in your organization. You can check simple facts (e.g. account consists only of numeric or alphabetic characters) or more complex compositions.
Regular expressions to check simple facts
We compiled some examples, which you may use to check some simple facts.
The account must include:
Only numeric characters: ^[0-9]+$
Only alphabetic characters: ^[a-zA-Z]+$
Only numeric characters and points: ^[0-9.]+$
Only numeric characters, points and blank spaces: ^[0-9. ]+$
Only numeric characters, points, blank spaces and hyphens: ^[0-9. \-]+$
6 numeric characters exactly: ^[0-9]{6}$
6 alphabetic characters exactly: ^[a-zA-Z]{6}$
6 characters (numeric & alphabetics) exactly: ^[0-9a-zA-Z]{6}$
3 numeric characters minimum: ^[0-9]{3,}$
3 alphabetic characters minimum: ^[a-zA-Z]{3,}$
3 characters (numeric & alphabetics) minimum: ^[0-9a-zA-Z]{3,}$
Regular expressions to check more complex facts
Here are two more complex queries:
The account begins with 3 alphabetic characters and ends with 3 numeric characters. There can be other numeric or alphabetic characters in between:
^[A-Za-z]{3}[0-9a-zA-Z]+[0-9]{3}$
The account has the following composition: abc-xxxx-123 (3 alphabetic characters, hyphen, 4 characters (numeric & alphabetic), hyphen, 3 numeric characters)
^[A-Za-z]{3}[\-][0-9a-zA-Z]{4}[\-][0-9]{3}$
You can find more examples and a helpful tutorial at rexegg.com.
Testing of regular expressions
Before you use a regular expression for the validation of the account field, you should test it extensively.
It can be very frustrating for your users, if they want to enter a correct account, but the input is rejected because of a wrong regular expression. As the account field is mandatory, in this case they would not be able to complete their order.
To avoid those conflicts, we included a dedicated field you can use for testing. There you can enter different syntax variations and you see immediately, if they are okay or if they would be rejected.