English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi, I have this Javascript, but to be honest, I'm exactly sure what it means. I know that it's an email validator function, but what is the "elements" part? What does "(!(emailPattern.test(email)))" mean?

Thanks again for all the brains out there!!!

function emailTest(emailText)
{
var email = emailText.value;
var emailPattern = /^.+@.+\..{2,}$/;
if (!(emailPattern.test(email)))

{
alert("Please enter a valid email address.");
document.myForm.elements[1].focus();
}
}

2007-11-15 06:12:03 · 2 answers · asked by J L 1 in Computers & Internet Programming & Design

2 answers

The "elements" part is part of the DOM.

document is your whole page
myForm is a particular form within document
elements is an array of form elements within myForm (e.g. text fields, checkboxes, etc.)
elements[1] is the second form element in the array.

The emailPattern.test part is checking to see if the entered email address is formed correctly - e.g. someone@somewhere.com.

2007-11-15 06:44:21 · answer #1 · answered by daa 7 · 0 0

it's using a regular expression to test for certain chars in the e-mail string.

2007-11-15 14:19:39 · answer #2 · answered by fixedinseattle 4 · 0 0

fedest.com, questions and answers