I am exploring the use of HTML5's type="email"
validation to develop a function for validating email addresses.
My goal is to create a form and add an input that has its type set as email
. By attempting to submit the form, I aim to determine whether the entered email address is valid or not.
Although my initial approach did not work as expected:
function isEmail (string) {
var frm = document.createElement('form');
var input = document.createElement('input');
input.setAttribute('type', 'email');
input.setAttribute('action', 'javascript:void(0)');
input.setAttribute('value', string);
frm.appendChild(input);
// My original attempt didn't yield the desired result
if ( !! frm.submit() ) return true;
else return false;
}
Can an email address be validated using this method?