如何在文本域Appcelerator中输入文本后验证电子邮件

时间:2021-09-27 20:39:59

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.

我是appcelerator的新手。我有个疑问。在文本字段中输入文本后,是否有人知道如何检查电子邮件验证。我可以通过点击按钮来完成。但我想要的是,需要在输入文本后签入文本字段。任何帮助将深表感谢。

Thanks

1 个解决方案

#1


2  

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);
} 

#1


2  

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);
}