Skip to content

ashkan90/validator

Repository files navigation

About Package

Usage (Tested only with 'url.Values')

Using validator is easy as much as needed. Some Usage rules:

"name": "required|max:100|min:20|equal:Blabla"
"age": "required|digit|between:0-255"

There are three types of token


First one (Separator): ``|``
Second one (Value Input): ``:``
Third one (Value Separator): ``-``

fmt.Println(validator.Load(map[string]string{
		"name": "required|equal:Emirhan",
		"surname": "max:10",
		"age": "required|digit|between:0-255",
		"password": "required|confirmation:password_confirmation",
		"password_confirmation": "required",
		"today": "required|date",
	}, r.Form).Run())

You don't need to initialize bunch of unused structs. There's only simplicity

About Rules

Date:

date rule is just using 'Y-m-D' format currently.

"today": "required|date",

Max-Min:

As you can understand, max/min is checking for string's length. Strings are represented as character-bytes of array in memory like this: ['H', 'e', 'l', 'l', 'o', ' ', 'W'...] and we're counting its length then comparing with your rule input.

Features

  • Is array rule ('array')
  • Is string rule ('string')
  • Is integer and digit rules ('integer'|'digit')
  • Is between rule('between:x-y')
  • Is confirmed rule ('confirmed:Hello world') // case sensitive
  • Is date rule ('date') // uses Y-m-D format
  • [] date rule format and localization can be changed by user
  • Is file rule ('file')
  • [] Is file's max size grater than i decided to ?
  • [] Is file's min size lower than i decided to ?
  • [] Is field email ?
  • Errors messages can be internalization
  • [] Agnostic rule checkers
  • Any type form fields.
  • [] Tests