function invalidEventHandler(e)
{
is(e.type, "invalid", "Invalid event type should be invalid");
gInvalid = true;
}
function checkValidEmailAddress(element)
{
gInvalid = false;
ok(!element.validity.typeMismatch && !element.validity.badInput, "Element should not suffer from type mismatch or bad input (with value='"+element.value+"')");
ok(element.validity.valid, "Element should be valid");
ok(element.checkValidity(), "Element should be valid");
ok(!gInvalid, "The invalid event should not have been thrown");
is(element.validationMessage, '', "Validation message should be the empty string");
ok(element.matches(":valid"), ":valid pseudo-class should apply");
}
function checkInvalidEmailAddress(element, failedValidityStates)
{
info("Checking " + element.value);
gInvalid = false; var expectTypeMismatch = !!(failedValidityStates & TYPE_MISMATCH); var expectBadInput = !!(failedValidityStates & BAD_INPUT);
ok(element.validity.typeMismatch == expectTypeMismatch, "Element should " + (expectTypeMismatch ? "" : "not ") + "suffer from type mismatch (with value='"+element.value+"')");
ok(element.validity.badInput == expectBadInput, "Element should " + (expectBadInput ? "" : "not ") + "suffer from bad input (with value='"+element.value+"')");
ok(!element.validity.valid, "Element should not be valid");
ok(!element.checkValidity(), "Element should not be valid");
ok(gInvalid, "The invalid event should have been thrown");
is(element.validationMessage, "Please enter an email address.", "Validation message is not valid");
ok(element.matches(":invalid"), ":invalid pseudo-class should apply");
}
// Add all username legal characters individually to the list.
for (c of legalCharacters) {
values.push([c + "@bar.com", VALID]);
}
// Add the concatenation of all legal characters too.
values.push([legalCharacters + "@bar.com", VALID]);
// Add username illegal characters, the same way. var illegalCharacters = "()<>[]:;@\\, \t";
for (c of illegalCharacters) {
values.push([illegalCharacters + "@bar.com", TYPE_MISMATCH]);
}
// Add domain legal characters (except '.' and '-' because they are special).
for (c of legalCharacters) {
values.push(["foo@foo.bar" + c, VALID]);
}
// Add the concatenation of all legal characters too.
values.push(["foo@bar." + legalCharacters, VALID]);
// Add domain illegal characters.
illegalCharacters = "()<>[]:;@\\,!#$%&'*+/=?^_`{|}~ \t";
for (c of illegalCharacters) {
values.push(['foo@foo.ba' + c + 'r', TYPE_MISMATCH]);
}
values.forEach(function([value, valid, todo]) {
if (todo === true) {
email.value = value;
todo_is(email.validity.valid, true, "value should be valid");
} else {
testEmailAddress(email, value, false, valid);
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.