govals

package module
v0.0.0-...-8427af3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alpha

func Alpha(s string) (bool, error)

Alpha validate string contains letters only [a-zA-Z] this function return bool and error if value does not valid

func AlphaNumeric

func AlphaNumeric(s string) (bool, error)

AlphaNumeric validate string contains letters and number only [a-zA-Z0-9] this function return bool and error if value does not valid

func CustomValidate

func CustomValidate(val string, rule string) (bool, error)

CustomValidate is validate data value with custom rule, your can write your regexp custom rule

func Date

func Date(s string) (bool, error)

Date checking string format as date like mm-dd-yyyy or mm/dd/yyyy this function return bool and error if value does not valid

func Email

func Email(s string) (bool, error)

Email validate string if is valid email format, this function return bool and error if value does not valid

func Length

func Length(s int, min, max int) (bool, error)

Length is validate number length

func Numeric

func Numeric(s string) (bool, error)

Numeric validate string contains digits only [0-9] this function return bool and error if value does not valid

func PhoneNumber

func PhoneNumber(s string) (bool, error)

PhoneNumber checking string match phone number like +62828882888 or 082323333333 this function return bool and error if value does not valid

func RuneLength

func RuneLength(s string, min, max int) (bool, error)

RuneLength is validate text length

func Times

func Times(s string) (bool, error)

Times checking string format time like 12:00:01 or 12:00

Types

type StructVals

type StructVals struct {
	// contains filtered or unexported fields
}

func Struct

func Struct(s interface{}) *StructVals

Struct set new validator

func (*StructVals) GetStatus

func (gov *StructVals) GetStatus(str string) (bool, error)

GetStatus return validation bool and error of validation fields

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL