< Back
You are here:
Print

4.3.1 Client side validation

With most form elements you can add a client side validation by using a pattern. This pattern is made as a regular expression and is commonly used for validation in HTML.

With the client side validation the validation is done without contacting the server. There is no request send to the server in this case.

If you don’t know how to build a regular expression, there is a lot of info on the internet. Sometimes it can be rather complex if it is a complex validation.

“pattern”: “[ABC]{1}”

One character that has to be uppercase A, B or C.

“pattern”: “[A-Za-z]{3}”

Up to three characters which can be from A to Z, or a to z. So lower and uppercase are accepted.

“pattern”: “[\\d]{1,2}”

Only decimals are accepted with a lenght from 1 to 2. So a value from 0 up to 99 is valid.

\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b

The above is a pattern to check for a valid email address. As you can see this is more complex.

  • The first part means that it can contain all letters from A-Z (upper and lowercase), numbers and also the symbols ._%+-
  • It has to be followed by @
  • the next part is the domain name which can have A to Z, numbers and the characters . or –
  • It should be followed by a dot.
  • Last part can be A-Z and is at least two characters long.
Next 4.3.2 Server side validation
Table of Contents