定制 sielatchom/validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sielatchom/validator

最新稳定版本:v1.0.0

Composer 安装命令:

composer require sielatchom/validator

包简介

Simple PHP validation library

README 文档

README

PHP Version License Packagist Version Downloads

A simple, extensible, and developer-friendly PHP validation library
Validate forms and data easily with Laravel-style rules. Supports strings, numbers, dates, emails, passwords, phone numbers, URLs, JSON, and more.

Installation

Install via Composer:

composer require sielatchom/validator

Description

Sielatchom\Validator provides a simple API to validate PHP arrays, allowing developers to check multiple fields and rules with a single call.
It is PSR-4 compliant, unit-tested, and extensible

Usage

Basic Examples

<?php
require 'vendor/autoload.php';

use Sielatchom\Validator\Validator;

$data = [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'password' => 'Abc123$%',
    'password_confirmation' => 'Abc123$%',
    'age' => 25,
    'phone' => '237655123456',
    'website' => 'https://example.com',
    'payload' => '{"role":"admin"}',
    'dob' => '1990-01-01'
];

$validator = new Validator($data);

$validator->validate([
    'name'     => ['required', 'string', 'min:3', 'max:50'],
    'email'    => ['required', 'email'],
    'password' => ['required', 'password:8,strong', 'confirmed'],
    'age'      => ['integer', 'between:18,65'],
    'phone'    => ['phone:9,13'],
    'website'  => ['url'],
    'payload'  => ['json'],
    'dob'      => ['dateValidate', 'after:1900-01-01', 'before:today']
]);

if ($validator->fails()) {
    print_r($validator->errors());
} else {
    echo "All data is valid!";
}

Validation Rules Reference

Rule Description
required Field must exist and not be empty
email Must be a valid email address
password:min,strength Minimum length and optional strong password check (uppercase, lowercase, number, special)
phone:min,max Phone number digits range
date Validate date format (default Y-m-d)
after:min Date must be after a specific date or today
before:max Date must be before a specific date
string Field must be a string
numeric Field must be numeric
integer Field must be an integer
boolean Field must be boolean (true/false/1/0)
min:value Minimum string length or numeric value
max:value Maximum string length or numeric value
between:min,max Value must be within a given range
in:val1,val2,... Value must be one of the allowed options
confirmed Field must match its _confirmation field
regex:/pattern/ Field must match the given regex pattern
url Must be a valid URL
json Must be a valid JSON string

About the Author

Sielatchom Jeukeng Chrisaire Daryl

Lisense

This library is licensed under the MIT License.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04