Validation rule for component in Salesforce Lightning

Sample Code:
Component:

<aura:component >
<ui:inputNumber label="Contract No " aura:Id="contractNo" blur="{!c.validateContractNo}"/>
</aura:component>

Controller:

({
validateContractNo : function(component, event, helper) {
var inputCmp = component.find("contractNo");
var value = inputCmp.get("v.value");
        
        if ( value.length < 8 || value.length > 12 || isNaN(value) ) {
            inputCmp.set("v.errors", [{message:"Invalid Contract No: " + value}]);
        } else {
        inputCmp.set("v.errors", null);
        }
}
})

Cheers!!!

No comments:

Post a Comment