Giter Site home page Giter Site logo

govalidator's Introduction

govalidator

GoDoc Coverage Status views wercker status

A package of string validators and sanitizers for Go lang. Based on validator.js.

Installation

Make sure that Go is installed on your computer. Type the following command in your terminal:

go get github.com/asaskevich/govalidator

After it the package is ready to use.

List of functions:

func BlackList(str, chars string) string
func CamelCaseToUnderscore(str string) string
func Contains(str, substring string) bool
func Escape(str string) string
func GetLine(s string, index int) (string, error)
func GetLines(s string) []string
func IsASCII(str string) bool
func IsAlpha(str string) bool
func IsAlphanumeric(str string) bool
func IsBase64(str string) bool
func IsByteLength(str string, min, max int) bool
func IsCreditCard(str string) bool
func IsDivisibleBy(str, num string) bool
func IsEmail(str string) bool
func IsFloat(str string) bool
func IsFullWidth(str string) bool
func IsHalfWidth(str string) bool
func IsHexadecimal(str string) bool
func IsHexcolor(str string) bool
func IsIP(str string, version int) bool
func IsISBN(str string, version int) bool
func IsInt(str string) bool
func IsJSON(str string) bool
func IsLowerCase(str string) bool
func IsMAC(str string) bool
func IsMultibyte(str string) bool
func IsNull(str string) bool
func IsNumeric(str string) bool
func IsURL(str string) bool
func IsUUID(str string, version int) bool
func IsUpperCase(str string) bool
func IsVariableWidth(str string) bool
func LeftTrim(str, chars string) string
func Matches(str, pattern string) bool
func RemoveTags(s string) string
func ReplacePattern(str, pattern, replace string) string
func Reverse(s string) string
func RightTrim(str, chars string) string
func SafeFileName(str string) string
func StripLow(str string, keepNewLines bool) string
func ToBoolean(str string) (bool, error)
func ToFloat(str string) (float64, error)
func ToInt(str string) (int64, error)
func ToString(obj interface{}) (string, error)
func Trim(str, chars string) string
func UnderscoreToCamelCase(s string) string
func ValidateStruct(s interface{}) bool
func WhiteList(str, chars string) string

Examples

IsURL
println(govalidator.IsURL(`http://user@pass:domain.com/path/page`))
ToString
type User struct {
	FirstName string
	LastName string
}

str,_ := govalidator.ToString(&User{"John", "Juan"})
println(str)
ValidateStruct
type Post struct {
    Title    string `^[a-zA-Z0-9]{10,50}$`
    Message  string
    AuthorIP string `^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$"`
}
post := &Post{"My Post about Examples", "Some text", "123.234.54.3"}
println(govalidator.ValidateStruct(post) == true)
WhiteList
// Remove all characters from string ignoring characters between "a" and "z"
println(govalidator.WhiteList("a3a43a5a4a3a2a23a4a5a4a3a4", "a-z") == "aaaaaaaaaaaa")

Notes

Documentation is available here: godoc.org. Full information about code coverage is also available here: govalidator on gocover.io.

Support

If you do have a contribution for the package feel free to put up a Pull Request or open Issue.

govalidator's People

Contributors

asaskevich avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.