-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
51 lines (45 loc) · 1.43 KB
/
web.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Implements verifications for the web.
package verify
import "regexp"
const (
emailRegexp string = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9]" +
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9]" +
"(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
urlRegexp string = "^" +
// protocol identifier
"(?:(?:https?|ftp)://)" +
// user:pass authentication
"(?:\\S+(?::\\S*)?@)?" +
// host name
"(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)" +
// domain name
"(?:\\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*" +
// TLD identifier
"(?:\\.(?:[a-z\u00a1-\uffff]{2,}))" +
// port number
"(?::\\d{2,5})?" +
// resource path
"(?:/[^\\s]*)?" +
"$"
)
// verifies an email
// as with all regex-based email validations, this may return inaccurate results
func (v *verifier) Email() *verifier {
result := regexp.MustCompile(emailRegexp).MatchString(v.Query)
return v.addVerification("Email", result)
}
// inverse verification of an email
func (v *verifier) IsntEmail() *verifier {
result := regexp.MustCompile(emailRegexp).MatchString(v.Query)
return v.addVerification("Email", !result)
}
// verifies a url
func (v *verifier) Url() *verifier {
result := regexp.MustCompile(urlRegexp).MatchString(v.Query)
return v.addVerification("Url", result)
}
// verifies a url
func (v *verifier) IsntUrl() *verifier {
result := regexp.MustCompile(urlRegexp).MatchString(v.Query)
return v.addVerification("Url", !result)
}