https://github.com/0xwal/lua-varguard
Laravel-like validator.
https://github.com/0xwal/lua-varguard
guard lua validation
Last synced: 7 months ago
JSON representation
Laravel-like validator.
- Host: GitHub
- URL: https://github.com/0xwal/lua-varguard
- Owner: 0xwal
- License: mit
- Created: 2021-05-04T03:30:46.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-05T13:27:04.000Z (almost 4 years ago)
- Last Synced: 2025-01-30T03:43:53.367Z (8 months ago)
- Topics: guard, lua, validation
- Language: Lua
- Homepage:
- Size: 18.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-varguard
Simple API to validate input inspired by [PHP-Laravel](https://laravel.com/docs/8.x/validation) framework.
## Usage
```lua
require('varguard')function rule_email(value, args)
-- check if not email return false
return false
endlocal rules = {
name = 'required|type:string',
email = 'required|type:string|email',
['address.country'] = 'required',
['address.city'] = 'required'
}local data = {
name = 'lua',
email = 'not-email',
address = {
country = 'SA',
-- city = 'RY'
}
}local validation = VarGuard(rules, data)
local isValid, values = validation:validate()
-- isValid == status of validation
print(validation:passes())
print(#validation:errors())
```## Todo
* Add more rules.
* Support Array of Objects