Skip to content

Commit 78279e7

Browse files
committed
Add other rules network and edit document
1 parent 6239d2e commit 78279e7

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ This project is currently in development, and additional features will be added
55

66
Stay tuned for upcoming enhancements!
77

8+
9+
### Network:
10+
11+
| Tag | Description |
12+
| - | - |
13+
| ip | Internet Protocol Address IP |
14+
| ipv4 | Internet Protocol Address IPv4 |
15+
| ipv6 | Internet Protocol Address IPv6 |
16+
| mac | Media Access Control Address MAC |
17+
| uri | URI String |
18+
| url | URL String |
19+
820
## more
921

1022
I developed this project to deepen my understanding of Go and its capabilities. It's an opportunity for me to explore Go's features and enhance my skills in building more efficient and flexible systems.

pkg/validation/rules_network.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ func validationIsURL(value string, errorMsg string) error {
1313
return nil
1414
}
1515

16+
func validationIsURI(value string, errorMsg string) error {
17+
uriRegex := `^([a-zA-Z0-9\-.]+)$`
18+
if matched, _ := regexp.MatchString(uriRegex, value); !matched {
19+
return errors.New(errorMsg)
20+
}
21+
return nil
22+
}
23+
1624
func validationIsIPv4(value string, errorMsg string) error {
1725
ipRegex := `^(\d{1,3}\.){3}\d{1,3}$`
1826
if matched, _ := regexp.MatchString(ipRegex, value); !matched {
@@ -37,3 +45,11 @@ func validationIsIP(value string, errorMsg string) error {
3745
}
3846
return nil
3947
}
48+
49+
func validationIsMacAddress(value string, errorMsg string) error {
50+
macRegex := `^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$`
51+
if matched, _ := regexp.MatchString(macRegex, value); !matched {
52+
return errors.New(errorMsg)
53+
}
54+
return nil
55+
}

pkg/validation/validator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ var validators = map[string]interface{}{
2727
"btcaddress": validationIsBtcAddress,
2828
//bank
2929
"bic": validationIsBIC,
30-
//ip
30+
//network
3131
"ipv4": validationIsIPv4,
3232
"ipv6": validationIsIPv6,
33+
"ip": validationIsIP,
34+
"mac": validationIsMacAddress,
35+
"uri": validationIsURI,
36+
"url": validationIsURL,
3337
//url
34-
"url": validationIsURL,
3538
"email": validateIsEmail,
3639
}
3740

0 commit comments

Comments
 (0)