function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Niraj Singh 28Niraj Singh 28 

set validity not working on lightning component

Hello All,

I have needed to modify validity value of an input but not getting modified after setting this value. Please have a look on my code suggest what i am doing wrong here.
IsValid:function(cmp,evt,helper){
        var contactFields=cmp.find("contactField");
        var blank=0;
        blank++;        
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;        
        if(contactFields.length != undefined){           
            var allvalid=contactFields.reduce(function(validSoFar,inputCmp){                
                inputCmp.showHelpMessageIfInvalid();
                if(inputCmp.get("v.name")=='VSMemail'){
                    var conEmail=inputCmp.get("v.VSMemail");
                    if(reg.test(conEmail) == false)
                    {  
                        inputCmp.set('v.validity', {valid:false, badInput :true}); 
                        
                    }
                }
                return validSoFar && inputCmp.get("v.validity").valid;
            },true); 
            return allvalid;
        }