https://github.com/hasanaliqureshi/go-validation
Text and Input Validation in Golang
https://github.com/hasanaliqureshi/go-validation
go golang golang-application input-validation learning-by-doing validation validation-library
Last synced: 27 days ago
JSON representation
Text and Input Validation in Golang
- Host: GitHub
- URL: https://github.com/hasanaliqureshi/go-validation
- Owner: hasanaliqureshi
- Created: 2018-11-30T05:23:37.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-01T13:36:23.000Z (about 7 years ago)
- Last Synced: 2024-06-21T13:12:48.989Z (over 1 year ago)
- Topics: go, golang, golang-application, input-validation, learning-by-doing, validation, validation-library
- Language: Go
- Size: 5.86 KB
- Stars: 23
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# Text and Input Validation in Golang
I've created this helping script for my APIs to deal with user inputs. Just clone the repo and use it in your project.
## Usage:
1. Define the validator
`
userInput := validator("blah!blah!blah!")
`
2. Apply the methods
`userInput.Required().oneLowerCase().check()` `// will return true or false`
## Methods
use `.check()` after all methods to return the `boolean` value, otherwise the method will return `type struct`
| Methods | Descrption |
| ------------------ | :----------------------------------------------------------- |
| Required() | returns `false` if input is empty |
| minLength(int) | returns `false` if input is less than provided minimum value |
| maxLength(int) | returns `false` if input is greater than provided maximum value |
| isEmail | return `false` if input is not an email address |
| oneLowerCase | return `false` if input value doesn't have at least one lowercase character |
| allLowerCase | return `false`if input value doesn't have all lowercase characters |
| oneUpperCase | return `false` if input value doesn't have at least one uppercase character |
| allUpperCase | return `false` if input value doesn't have all uppercase characters |
| oneNumber | return `false` if input value doesn't have at least one number character |
| isSpecialCharacter | return `false` if input value doesn't have at least one special character |
## Using Multiple Methods:
I've design the methods in a way that multiple methods can be used in a line.
For example to check for a strong password you can use.
`userInput.minLength(8).oneLowerCase().oneUpperCase().oneNumber().isSpecialCharacter().check()`
The above code will check for the applied methods and will return boolean `false` if any method doesn't validate the password.