Server-side validation using Edit Validate rules
Let's start with a short tutorial to see how server-side validation works using Edit Validate rules.
Create the MobilePhone Edit Validate rule with the following Java Source:
// ************************** //
// Edit Validate: MobilePhone //
// ************************** //
java.util.regex.Pattern regex = java.util.regex.Pattern.compile("^[0-9]{9}$", java.util.regex.Pattern.CASE_INSENSITIVE);
java.util.regex.Matcher matcher = regex.matcher(theValue);
if (!matcher.find()) {
theProperty.addMessage("[server] The phone is invalid");
return false;
}
return true;
Create the .Phone property and set its "Use validate" option to MobilePhone.
Create the EmailAddress Edit Validate rule with the following Java Source:
// *************************** //
// Edit Validate: EmailAddress //
// *************************** //
java.util.regex.Pattern regex = java.util.regex.Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", java.util.regex.Pattern.CASE_INSENSITIVE);
java.util.regex.Matcher matcher = regex.matcher(theValue);
if( !matcher.find() ) {
theProperty.addMessage("[server] The email is invalid");
return false;
}
return true;
Create the .Email property and set its "Use validate" option to EmailAddress.
Create a section with the .Email and .Phone properties. Test it!
We can see that to validate the form the "Submit" button had to communicate with the server sending the submitted values, and then refresh the section to show the errors.
While server-side validation is necessary, the user will be able to receive feedback much faster through client-side validation.
Comments
Post a Comment