One Table, One Field with regexp validation Example

 

 

         The next easiest CRUD Liferay portlet we can do wil be a  portlet project called "xmlpfexampleB" where we want to create a users table maintenance, where the only field in use is "userEmail", a Varchar field of 50 that needs to be validated.  Some of the available regexp validations are:

 

  • float_regexp=[-+]?[0-9]*\.?[0-9]+$
  • integer_regexp=^[-+]?[0-9]+[0-9]*$
  • email=^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$
  • ip=^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
  • url=^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)( [a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$
  • zipspain=^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$
  • nifspain=[0-9]{8}[A-Za-z]
  • phonespain=^[0-9]{2,3}-? ?[0-9]{6,7}$
  • zero_to_ten=^([0-9]|10)$

         If you want to know more or expand regexp validations, you can get more information in Documentation / How-tos / Adding new regexp validations.

         Here you have how the portlet will look in the page with Liferays Classic theme.

          This is how the portlet will look in Edit mode.

  

          This is how the portlet will look after adding a record.

 

          This is how the portlet will look after trying to add a record and validation regexp rejected it.

          Here you have the full XMLPortletFactory xml file.

                        XMLPFExample02.xml

 

          And here you have the portlet war generated. (for liferay 6.0.6)

                        xmlpfexampleB-portlet-6.0.6.1.war

                             

          If you want to use this example you can follow instructions here DOCUMENTATION