示例#1
0
bool ValidityState::typeMismatch() const
{
    if (!m_control->hasTagName(inputTag))
        return false;

    HTMLInputElement* input = static_cast<HTMLInputElement*>(m_control);
    String value = input->value();

    if (value.isEmpty())
        return false;

    switch (input->inputType()) {
    case HTMLInputElement::COLOR:
        return !isValidColorString(value);
    case HTMLInputElement::NUMBER:
        return !parseToDoubleForNumberType(value, 0);
    case HTMLInputElement::URL:
        return !KURL(KURL(), value).isValid();
    case HTMLInputElement::EMAIL: {
        if (!input->multiple())
            return !isValidEmailAddress(value);
        Vector<String> addresses;
        value.split(',', addresses);
        for (unsigned i = 0; i < addresses.size(); ++i) {
            if (!isValidEmailAddress(addresses[i]))
                return true;
        }
        return false;
    }
    case HTMLInputElement::DATE:
    case HTMLInputElement::DATETIME:
    case HTMLInputElement::DATETIMELOCAL:
    case HTMLInputElement::MONTH:
    case HTMLInputElement::TIME:
    case HTMLInputElement::WEEK:
        return !HTMLInputElement::parseToDateComponents(input->inputType(), value, 0);
    case HTMLInputElement::BUTTON:
    case HTMLInputElement::CHECKBOX:
    case HTMLInputElement::FILE:
    case HTMLInputElement::HIDDEN:
    case HTMLInputElement::IMAGE:
    case HTMLInputElement::ISINDEX:
    case HTMLInputElement::PASSWORD:
    case HTMLInputElement::RADIO:
    case HTMLInputElement::RANGE:
    case HTMLInputElement::RESET:
    case HTMLInputElement::SEARCH:
    case HTMLInputElement::SUBMIT:
    case HTMLInputElement::TELEPHONE: // FIXME: Is there validation for <input type=telephone>?
    case HTMLInputElement::TEXT:
        return false;
    }

    ASSERT_NOT_REACHED();
    return false;
}
bool EmailInputType::typeMismatchFor(const String& value) const
{
    if (value.isEmpty())
        return false;
    if (!element()->multiple())
        return !isValidEmailAddress(value);
    Vector<String> addresses;
    value.split(',', true, addresses);
    for (unsigned i = 0; i < addresses.size(); ++i) {
        if (!isValidEmailAddress(stripLeadingAndTrailingHTMLSpaces(addresses[i])))
            return true;
    }
    return false;
}
// The return value is an invalid email address string if the specified string
// contains an invalid email address. Otherwise, null string is returned.
// If an empty string is returned, it means empty address is specified.
// e.g. "[email protected],,[email protected]" for multiple case.
String EmailInputType::findInvalidAddress(const String& value) const
{
    if (value.isEmpty())
        return String();
    if (!element().multiple())
        return isValidEmailAddress(value) ? String() : value;
    Vector<String> addresses;
    value.split(',', true, addresses);
    for (unsigned i = 0; i < addresses.size(); ++i) {
        String stripped = stripLeadingAndTrailingHTMLSpaces(addresses[i]);
        if (!isValidEmailAddress(stripped))
            return stripped;
    }
    return String();
}
示例#4
0
/* determines the validity of a given email addresses,
   writing the result out to the screen. */
void print_validity(char * address, char** terminators,
                    int length)
{
  printf("The string %s is ", address);
  if (isValidEmailAddress(address, terminators, length) == 0) {
    printf("not ");
  }
  printf("a valid email address\n");
}