summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/html/ValidityState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/webkit/WebCore/html/ValidityState.cpp')
-rw-r--r--src/3rdparty/webkit/WebCore/html/ValidityState.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/3rdparty/webkit/WebCore/html/ValidityState.cpp b/src/3rdparty/webkit/WebCore/html/ValidityState.cpp
index df8933da42..6b0a0b4a08 100644
--- a/src/3rdparty/webkit/WebCore/html/ValidityState.cpp
+++ b/src/3rdparty/webkit/WebCore/html/ValidityState.cpp
@@ -26,6 +26,12 @@
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "KURL.h"
+#include "RegularExpression.h"
+#include <wtf/StdLibExtras.h>
+
+#define EMAIL_LOCALPART "[a-z0-9!#$%&'*+/=?^_`{|}~.-]+"
+#define EMAIL_DOMAINPART "[a-z0-9-]+(\\.[a-z0-9-]+)+"
+#define EMAIL_PATTERN EMAIL_LOCALPART "@" EMAIL_DOMAINPART
namespace WebCore {
@@ -55,11 +61,38 @@ bool ValidityState::typeMismatch()
return !HTMLInputElement::formStringToDouble(value, 0);
case HTMLInputElement::URL:
return !KURL(KURL(), value).isValid();
+ case HTMLInputElement::EMAIL:
+ {
+ if (!input->multiple())
+ return !isValidEmailAddress(value);
+
+ Vector<String> email_list;
+ value.split(',', email_list);
+ for (unsigned i = 0; i < email_list.size(); ++i)
+ if (!isValidEmailAddress(email_list[i]))
+ return true;
+
+ return false;
+ }
default:
return false;
}
}
+bool ValidityState::rangeUnderflow()
+{
+ if (!control()->hasTagName(inputTag))
+ return false;
+ return static_cast<HTMLInputElement*>(control())->rangeUnderflow();
+}
+
+bool ValidityState::rangeOverflow()
+{
+ if (!control()->hasTagName(inputTag))
+ return false;
+ return static_cast<HTMLInputElement*>(control())->rangeOverflow();
+}
+
bool ValidityState::valid()
{
bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
@@ -81,4 +114,19 @@ bool ValidityState::isValidColorString(const String& value)
return color.isValid() && !color.hasAlpha();
}
+bool ValidityState::isValidEmailAddress(const String& email)
+{
+ if (email.isEmpty())
+ return false;
+
+ DEFINE_STATIC_LOCAL(AtomicString, emailPattern, (EMAIL_PATTERN));
+ DEFINE_STATIC_LOCAL(RegularExpression, regExp, (emailPattern, TextCaseInsensitive));
+
+ int matchLength = 0;
+ int emailLength = email.length();
+ int matchOffset = regExp.match(email, 0, &matchLength);
+
+ return matchOffset == 0 && matchLength == emailLength;
+}
+
} // namespace