LifeRay creating a new type of aui validator

吃可爱长大的小学妹 提交于 2019-12-13 06:24:49

问题


I want to create a new type of aui validator. For example :

<aui:input name="firstName" type="text" maxlength="40">
    <aui:validator name="required" />
    <aui:validator name="alpha" />
</aui:input>

the alpha validator does not accept the space character, i want to use a type that accepts alpha characters plus the space character, i have already a solution using javascript to use a custom validator, but i want to define a new validator type to use like the others by invoking the validator tag e.g :

<aui:validator name="myValidator" />

Is that possible ?! and how can i do it ;)


回答1:


Try your luck on it :)

<aui:input name="firstName" type="text">
    <aui:validator name="myValidator" errorMessage="numbers-not-allowed">
        function(val, fieldNode, ruleValue){ 
            var matches = val.match(/\d+/g);
            if(matches != null)
                return false;
            else
                return true;
       }
    </aui:validator>
</aui:input>


来源:https://stackoverflow.com/questions/20548181/liferay-creating-a-new-type-of-aui-validator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!