aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/str.rs
diff options
context:
space:
mode:
authorbors-servo <servo-ops@mozilla.com>2020-04-02 08:07:30 -0400
committerGitHub <noreply@github.com>2020-04-02 08:07:30 -0400
commita651bad838e0fc87ea199ff0ec81d53a97bd61dd (patch)
treef3dac563783cfeaa5ca69851c426d7e7b4dff9c3 /components/script/dom/bindings/str.rs
parente47e884cc738a5cb472416a4fbdd9d2a32a2385c (diff)
parent779552ee7ddbbde1055c7202e16b9a13c3961988 (diff)
downloadservo-a651bad838e0fc87ea199ff0ec81d53a97bd61dd.tar.gz
servo-a651bad838e0fc87ea199ff0ec81d53a97bd61dd.zip
Auto merge of #25447 - teapotd:form-validation, r=jdm
Form constraint validation It's almost done, there are few things remaining: - ~Range underflow, range overflow and step mismatch implementation require #25405~ - ~There are some test failures due to missing DOM parts (#25003)~ - ~`pattern` attribute uses JS regexp syntax. Currently I used regex crate, but it's probably incompatible. Should we use SpiderMonkey's regexp via jsapi?~ - Currently validation errors are reported using `println!`. Are there any better options? - ~["While the user interface is representing input that the user agent cannot convert to punycode, the control is suffering from bad input."](https://html.spec.whatwg.org/multipage/#e-mail-state-(type%3Demail)%3Asuffering-from-bad-input)~ r? @jdm --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #11444 - [x] There are tests for these changes
Diffstat (limited to 'components/script/dom/bindings/str.rs')
-rw-r--r--components/script/dom/bindings/str.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs
index 986554206b6..0905c157143 100644
--- a/components/script/dom/bindings/str.rs
+++ b/components/script/dom/bindings/str.rs
@@ -519,6 +519,28 @@ impl DOMString {
// Step 7, 8, 9
Ok((date_tuple, time_tuple))
}
+
+ /// https://html.spec.whatwg.org/multipage/#valid-e-mail-address
+ pub fn is_valid_email_address_string(&self) -> bool {
+ lazy_static! {
+ static ref RE: Regex = Regex::new(concat!(
+ r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?",
+ r"(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
+ ))
+ .unwrap();
+ }
+ RE.is_match(&self.0)
+ }
+
+ /// https://html.spec.whatwg.org/multipage/#valid-simple-colour
+ pub fn is_valid_simple_color_string(&self) -> bool {
+ let mut chars = self.0.chars();
+ if self.0.len() == 7 && chars.next() == Some('#') {
+ chars.all(|c| c.is_digit(16))
+ } else {
+ false
+ }
+ }
}
impl Borrow<str> for DOMString {