Is there an easy way to do pattern matching validation on fields such as an edit box?
To enable pattern matching on an edit box:
- Go to the All Properties tab
- Click into the validators property
- Click the add button that appears and choose xp:validateConstraint
- Click into the regex property. It will give you a combo with the options:
- AlnumOnly (meaning [A-Za-z0-9])
If you choose one of those options, it will validate correspondingly using client-side validation, with a pop-up dialog appearing when the condition is not met,
or if the edit box has disableClientSideValidation="true" then you have to add a Display Error or Display Errors control to the page, and it will perform a server-side validation.
That is, when you submit, it will do a round-trip to the server and the page will be returned with the error message displayed in yellow box where the Display Error(s) control is placed.
You can also enter a regular expression in the regex property, using the regular expression format defined in java.util.regex.Pattern
However there is no client-side validation for regular expressions, so it will not give a pop-up dialog in the browser,
instead you must add a Display Error(s) control, and the message will display in the yellow box.