Skip to main content

VFormat RegEx

Goal: Usability

Developer: Carlos Ruiz

Description:

Now you can add validation for Strings based on regular expressions using the VFormat definition.

This is achieved simply adding a VFormat starting with the prefix ~ and followed by the regular expression that you want to apply.

For example, the following regular expression can be used to validate Spanish person names:

^[A-Za-záéíóúÁÉÍÓÚñÑüÜ][A-Za-záéíóúÁÉÍÓÚñÑüÜ\s-]*$

But, to put it in the VFormat you must add the ~ prefix, like this:

~^[A-Za-záéíóúÁÉÍÓÚñÑüÜ][A-Za-záéíóúÁÉÍÓÚñÑüÜ\s-]*$

01 VFormat

This is what the user would see when entering an invalid Name:

02 Error

Furthermore, if you want to supply the user a more friendly error message you can define a Message for the regular expression itself, just the regular expressions, without the ~ prefix:

03 Message

And now the user would see the error like:

04 Error

Technical Info: IDEMPIERE-6096


Source: Wiki