AUI validation for phone number, special characters(only +, - and space )

In below example, just shown how to validate phone number using required special characters

<aui:input type="text"   name="phoneNumber" label="PhoneNumber" >

  <aui:validator name="custom"  errorMessage="You can enter a maximum of 30 numeric and special  ( only +, - and space ) characters">

  <aui:validator name="maxLength">30</aui:validator>

  function (val, fieldNode, ruleValue) {
  var returnValue = true;
  var iChars = "~`!@#$%^&*()_=[]\\\';,./{}|\":<>?qwertyuiopasdfghjklzxcvbnm";
                for (var i = 0; i < val.length; i++) {
                    if (iChars.indexOf(val.charAt(i)) != -1) {                
                     returnValue = false;
                    }
                }
                return returnValue;
        }
    </aui:validator>
</aui:input>


Explanation :

  • Give input type, name, label.
  • mention validator name as custom , display error message according to your requirement.
  • specify the length of digits, on requirement.
  • start writing function, In above example in a text box I need user to enter only numeric & should allow space, - & + special character. so i have removed +, - symbols in iChars variable.
  • If you people need *,=,{, like these symbols to use, just remove this characters from iChars .


Comments

Popular posts from this blog

AUI Form In LifeRay

LifeRay 7 with Single Page Application (SPA) features & SennaJs !!! How It works? In LR7 & LR6.2..

Hide Default Liferay Error Message in login.jsp (HOOK)