Skip to content

Commit

Permalink
Add other rules network and edit document
Browse files Browse the repository at this point in the history
  • Loading branch information
debug-ing committed Nov 16, 2024
1 parent 6239d2e commit 78279e7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ This project is currently in development, and additional features will be added

Stay tuned for upcoming enhancements!


### Network:

| Tag | Description |
| - | - |
| ip | Internet Protocol Address IP |
| ipv4 | Internet Protocol Address IPv4 |
| ipv6 | Internet Protocol Address IPv6 |
| mac | Media Access Control Address MAC |
| uri | URI String |
| url | URL String |

## more

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.
Expand Down
16 changes: 16 additions & 0 deletions pkg/validation/rules_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ func validationIsURL(value string, errorMsg string) error {
return nil
}

func validationIsURI(value string, errorMsg string) error {
uriRegex := `^([a-zA-Z0-9\-.]+)$`
if matched, _ := regexp.MatchString(uriRegex, value); !matched {
return errors.New(errorMsg)
}
return nil
}

func validationIsIPv4(value string, errorMsg string) error {
ipRegex := `^(\d{1,3}\.){3}\d{1,3}$`
if matched, _ := regexp.MatchString(ipRegex, value); !matched {
Expand All @@ -37,3 +45,11 @@ func validationIsIP(value string, errorMsg string) error {
}
return nil
}

func validationIsMacAddress(value string, errorMsg string) error {
macRegex := `^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$`
if matched, _ := regexp.MatchString(macRegex, value); !matched {
return errors.New(errorMsg)
}
return nil
}
7 changes: 5 additions & 2 deletions pkg/validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ var validators = map[string]interface{}{
"btcaddress": validationIsBtcAddress,
//bank
"bic": validationIsBIC,
//ip
//network
"ipv4": validationIsIPv4,
"ipv6": validationIsIPv6,
"ip": validationIsIP,
"mac": validationIsMacAddress,
"uri": validationIsURI,
"url": validationIsURL,
//url
"url": validationIsURL,
"email": validateIsEmail,
}

Expand Down

0 comments on commit 78279e7

Please sign in to comment.