Sample example


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>

<aui:form name="fm2" action="" method="post">
<table>
<tr>
<td>
<aui:input name="phoneNumber" value='${phoneNumber}' label="Enter number#" inlineLabel="left">
           <!-- Pre defined validation -->
        <aui:validator name="required"  errorMessage="Phone number format as (xxx) xxx-xxxx"  />
        <aui:validator name="minLength" errorMessage="Phone number format as (xxx) xxx-xxxx" >14</aui:validator>
        <aui:validator name="maxLength" errorMessage="Phone number format as (xxx) xxx-xxxx" >14</aui:validator>
</aui:input>
</td>
<td>
<aui:input name="phoneNumber" value='${phoneNumber}' label="Enter number#" inlineLabel="left">
           <!-- Custom validation -->
 <aui:validator name="required"  errorMessage="Phone number format as (xxx) xxx-xxxx"  />
 <aui:validator name="custom" errorMessage="Please check term of use">
function (val, fieldNode, ruleValue) {
var result = false;

if (val == "true") {
result = true;
}
return result;
}
</aui:validator>
</aui:input>
</td>
<td>
<aui:button type="submit" name="numberSearch" value="Number Search" />
</td>
</tr>
</table>
</aui:form>

Validator file path : %LIFERAY_HOME%\webapps\ROOT\html\js\liferay\form.js

DEFAULTS FORM VALIDATOR STRINGS:

DEFAULT: Liferay.Language.get(‘please-fix-this-field’),
acceptFiles: Liferay.Language.get(‘please-enter-a-file-with-a-valid-extension-x’),
alpha: Liferay.Language.get(‘please-enter-only-alpha-characters’),
alphanum: Liferay.Language.get(‘please-enter-only-alphanumeric-characters’),
date: Liferay.Language.get(‘please-enter-a-valid-date’),
digits: Liferay.Language.get(‘please-enter-only-digits’),
email: Liferay.Language.get(‘please-enter-a-valid-email-address’),
equalTo: Liferay.Language.get(‘please-enter-the-same-value-again’),
max: Liferay.Language.get(‘please-enter-a-value-less-than-or-equal-to-x’),
maxLength: Liferay.Language.get(‘please-enter-no-more-than-x-characters’),
min: Liferay.Language.get(‘please-enter-a-value-greater-than-or-equal-to-x’),
minLength: Liferay.Language.get(‘please-enter-at-list-x-characters’),
number: Liferay.Language.get(‘please-enter-a-valid-number’),
range: Liferay.Language.get(‘please-enter-a-value-between-x-and-x’),
rangeLength: Liferay.Language.get(‘please-enter-a-value-between-x-and-x-characters-long’),
required: Liferay.Language.get(‘this-field-is-required’),
url: Liferay.Language.get(‘please-enter-a-valid-url’)

About these ads

Comments on: "AUI form Validation using AUI Validation tag library" (6)

  1. jossmy said:

    hey thank you very much for your input, but I have a question, what happens is that the alpha type space does not permit me to give, then wanted to know if there is any other way I can receive only letters but also spaces, thanks for your attention and for your contribution

    • Hi Jossmy,

      Sorry for the late reply.

      Yes, it is possible to achieve this we need to write our own custom rule. Have a look on the below example
      I hope its helps you.

      <aui:input type="text"	name="name" label="Name" >
      	<aui:validator name="required"/>
      	<aui:validator name="custom"  errorMessage="Please enter alpha only">
      		function (val, fieldNode, ruleValue) {
      				var returnValue = true;
      				var iChars = "~`!@#$%^&*()_+=-[]\\\';,./{}|\":<>?0123456789";
      				for (var i = 0; i < val.length; i++) {
      					if (iChars.indexOf(val.charAt(i)) != -1) {					
      					 returnValue = false;
      					}
      				}
      				return returnValue;
      		}
      	</aui:validator>
      </aui:input>
      

  2. jossmy said:

    hey you’re great, thank you very much served me much, really I am very grateful

  3. Thank you so much buddy… thanks a lot

  4. Shahbaz Khan said:

    How to do checkbox validation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: