fn-code / govals

Go library for validate data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Govals

Govals is a go/golang package for validate data, using struct and etc. govals have custom function like validate email, numeric, alpha, alpha numeric, date, time, phone number, and length of int or string, i hope soon i will add more function for validate data.

Example

example how to use govals, you can open folder example

Usage

Run this command go get github.com/fn-code/govals to use this library

  • Basic Functions

    this is basic function you can use to validate your data:
    ok, err := govals.Length(1000, 2, 10)
    if err != nil {
        log.Println(err)
    }
    if !ok {
        // bla bla bla
    }
  • Struct

    in struct you can use govals tag like this:
    Name    string `govals:"len, max=22, min=10"`
    Age     int8   `govals:"len, min=18, max=20"`
    Email   string `govals:"email"`
    Date    string `govals:"date"`
    Times   string `govals:"time"`
    Hoby    string `govals:"alpha"`
    Max     string `govals:"numeric"`
    Text    string `govals:"alphaNumeric"`
    Phone   string `govals:"phone"`
    Address string `govals:"custom, regex=[^(a-zA-Z)]"`
    • len, min=10, max=22 validate length of string or int
    • email validate string of email
    • date validate date of string if match, like 09-12-1996 or 09/12/1996
    • time validate time if match, like 12:00:01 or 12:01
    • alphavalidate string if contains alpha character
    • numericvalidate string if contains numeric
    • alphaNumeric validate string if contains alpha numeric character
    • phone validate string if valid phone number format
    • custom validate custom rule, using regexp, you can write your own rule to validate data

About

Go library for validate data

License:GNU General Public License v3.0


Languages

Language:Go 100.0%