Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Custom form validation in liferay 6.2

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.01k
    Comment on it

    Liferay uses AlloyUI taglibs for front-end development and it provides inbuilt input field validation rules.

    Following are inbuild validation rules of alloy liferay :

    Here’s a list of form validation rules available for AlloyUI’s FormValidator:

    acceptFiles: Define accepted file types (Default:empty)

    alpha: Input field should contain only alphabetic characters (Default:none)

    alphanum: Input field should contain only alphanumeric characters (Default:false)

    date: Input field should contain only a date (Default:false)

    digits: Input field should contain only digits (Default:false)

    email: Input field should contain only an email address (Default:false)

    equalTo: Confirm input field’s values are equal to the specified value. (Default:empty)

    iri: Input field should contain only an International Rough Index (Default:false)

    max: Integer value is greater than the value. (Default:none)

    maxLength: Input field’s contents are greater than the count of characters specified (Default:empty)

    min: Determines if the integer value is less than the specified value (Default:none)

    minLength: Input field’s contents are less than the count of characters specified (Default:empty)

    number: Input field should contain only numeric values (Default:false)

    range: Integer value of the field is within the specified range (Default:none)

    rangeLength: Input field’s contents is within the specified range (Default:empty)

    required: Input field is required for submission (Default:false)

    url: Input field’s contents are a URL (Default:false)

    Now, Below example help to create custom form validation 

    Below example blocks the given email addresses:

     

    <aui:input  label="" name="emailAddress" placeholder="EMAIL">
           <aui:validator name="custom"            
                 errorMessage="Oops! We need a personal email address for access to the system.">
                function (val, fieldNode, ruleValue)
                     {
                      var result = true;
                       var blockEmail=["abuse@","admin@","billing@","compliance@","devnull@","dns@","ftp@","hostmaster@","inoc@","info@","ispfeedback@","ispsupport@","list-request@","list@","maildaemon@","noc@","no-reply@","noreply@","null@","phish@","phishing@","postmaster@","privacy@","registrar@","root@","security@","spam@","support@","sysadmin@","tech@","undisclosed-recipients@","unsubscribe@","usenet@","uucp@","webmaster@","www@"];
             var length = blockEmail.length;
            while(length--) {
                if (val.toLowerCase().indexOf(blockEmail[length])!=-1) {
                result= false;    
                           }
             }
                    val=$.trim(val);
                    $("#<portlet:namespace />emailAddress").val(val);
                    return result;
                  }
           </aui:validator>
    </aui:input>


     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: