Passed
Push — main ( 226e09...0f61b2 )
by Rushan
02:24 queued 12s
created

is.IPv4   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package is
2
3
import (
4
	"github.com/muonsoft/validation/validate"
5
)
6
7
// Email is used for simplified validation of an email address. It allows all values
8
// with an "@" symbol in, and a "." in the second host part of the email address.
9
func Email(value string) bool {
10
	return looseEmailRegex.MatchString(value)
11
}
12
13
// HTML5Email is used for validation of an email address based on pattern for HTML5
14
// (see https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).
15
func HTML5Email(value string) bool {
16
	return html5EmailRegex.MatchString(value)
17
}
18
19
// URL is used to check that value is a valid URL string. By default (if no schemas are passed),
20
// the function checks only for the http:// and https:// schemas. Use the schemas argument
21
// to configure the list of expected schemas. If an empty string is passed as a schema, then
22
// URL value may be treated as relative (without schema, e.g. "//example.com").
23
func URL(value string, schemas ...string) bool {
24
	return validate.URL(value, schemas...) == nil
25
}
26
27
// IP checks that a value is a valid IP address (IPv4 or IPv6). You can use a list
28
// of restrictions to additionally check for a restricted range of IPs.
29
// See validate.IPRestriction for details.
30
func IP(value string, restrictions ...validate.IPRestriction) bool {
31
	return validate.IP(value, restrictions...) == nil
32
}
33
34
// IPv4 checks that a value is a valid IPv4 address. You can use a list
35
// of restrictions to additionally check for a restricted range of IPs.
36
// See validate.IPRestriction for details.
37
func IPv4(value string, restrictions ...validate.IPRestriction) bool {
38
	return validate.IPv4(value, restrictions...) == nil
39
}
40
41
// IPv6 checks that a value is a valid IPv6 address. You can use a list
42
// of restrictions to additionally check for a restricted range of IPs.
43
// See validate.IPRestriction for details.
44
func IPv6(value string, restrictions ...validate.IPRestriction) bool {
45
	return validate.IPv6(value, restrictions...) == nil
46
}
47