Currently, I have set up an event listener to detect when a user enters an email address in a text box on an HTML website. It triggers an alert whenever it recognizes the input as an email address. However, the current setup detects the blur event and checks against a regex, leading to multiple alerts being displayed and inaccuracies in the detection process.
I am now looking to modify the event listener to specifically listen for when the tab key is pressed. Although I understand that KeyCodes are required for this task, I have limited experience with them. Additionally, the event listener operates dynamically within a Firefox AddOn that scans webpages, so it is not directly attached to a particular input field.
Code:
vrs_getWin.document.getElementsByTagName("body")[0].innerHTML = bodyContents;
var inputFields = vrs_getWin.document.getElementsByTagName("input");
for(inputC=0; inputC < inputFields.length; inputC++) {
var elementT = inputFields[inputC].getAttribute("id");
inputFields[inputC].addEventListener("blur", function(){
var emailPattern = /(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/g;
var resultEmail = emailPattern.test(vrs_getWin.document.getElementById(elementT).value);
if(result) {
prompts.alert(null, "Test", vrs_getWin.document.getElementById(elementT).value);
}
}, false);
}
Any assistance with implementing the desired functionality would be highly appreciated.