Html5 input types includes many new types.
(range , Email , date etc...)
For example :
<input type="url" >
I know that IE used to have regex store ( on one of its internal folders)
Question :
Can I see in what regexes does chrome use to validate the input ?
Is it under a viewable file or something ? / how can I see those regexs ?
I looked up the source code of Blink. Keep in mind I never saw it before today, so I might be completely off. Assuming I found the right place -
For type="url"
fields there is URLInputType
, with the code:
bool URLInputType::typeMismatchFor(const String& value) const
{
return !value.isEmpty() && !KURL(KURL(), value).isValid();
}
typeMismatchFor
is called from HTMLInputElement::isValidValue
bool HTMLInputElement::isValidValue(const String& value) const
{
if (!m_inputType->canSetStringValue()) {
ASSERT_NOT_REACHED();
return false;
}
return !m_inputType->typeMismatchFor(value) // <-- here
&& !m_inputType->stepMismatch(value)
&& !m_inputType->rangeUnderflow(value)
&& !m_inputType->rangeOverflow(value)
&& !tooLong(value, IgnoreDirtyFlag)
&& !m_inputType->patternMismatch(value)
&& !m_inputType->valueMissing(value);
}
KURL
seems like a proper implementation of a URL, used everywhere in Blink.
In comparison, the implementation for EmailInputType
, typeMismatchFor
calls isValidEmailAddress
, which does use a regex:
static const char emailPattern[] =
"[a-z0-9!#$%&'*+/=?^_`{|}~.-]+" // local part
"@"
"[a-z0-9-]+(\\.[a-z0-9-]+)*"; // domain part
static bool isValidEmailAddress(const String& address)
{
int addressLength = address.length();
if (!addressLength)
return false;
DEFINE_STATIC_LOCAL(const RegularExpression, regExp,
(emailPattern, TextCaseInsensitive));
int matchLength;
int matchOffset = regExp.match(address, 0, &matchLength);
return !matchOffset && matchLength == addressLength;
}
These elements and more can be found on the /html folder. It seems most of them are using proper parsing and checking of the input, not regular expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With