Search code examples
javascripttitanium-mobiletitanium-alloyappcelerator-mobile

How to validate email after text is entered in textfield Appcelerator


I am new in appcelerator. I have a doubt. Does anybody have any idea about how to check email validation after we entered text in text field. I can able to do by a button click. But what i want is that, need to check in text field itself after text is entered. Any help will be deeply appreciated.

Thanks


Solution

  • You can add a event listener on textfield.

    textField.addEventListener('return',function(e){
         if(isValidEmail(e.source.value)){
            //Email is valid
         }else{
            //Invalid Email
         }
    
    });
    
    
    function isValidEmail(email) { 
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    }