PHPackages                             samsonphp/validation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. samsonphp/validation

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

samsonphp/validation
====================

SamsonPHP validation module

0.0.2(9y ago)0582[1 PRs](https://github.com/SamsonPHP/validation/pulls)Open Software License (OSL) v 3.0JavaScript

Since Mar 18Pushed 9y ago2 watchersCompare

[ Source](https://github.com/SamsonPHP/validation)[ Packagist](https://packagist.org/packages/samsonphp/validation)[ Docs](http://samsonos.com/)[ RSS](/packages/samsonphp-validation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

SamsonPHP validation module
===========================

[](#samsonphp-validation-module)

SamsonPHP validation implementation

[![Latest Stable Version](https://camo.githubusercontent.com/af1e2d2b899d671b2697cd861985b24192cddd2b448532d0770a4ad404ab185e/68747470733a2f2f706f7365722e707567782e6f72672f53616d736f6e5048502f76616c69646174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/SamsonPHP/validation)[![Build Status](https://camo.githubusercontent.com/6bfe60bc018d40722feadd552a0cc6d65e8a490f1308a651755130a69d87cf75/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f53616d736f6e5048502f76616c69646174696f6e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SamsonPHP/validation/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/cd0b98c506f87952aee11c67b5b5bb3e4902e23dc022d1dbd0c559ab86c289d5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f53616d736f6e5048502f76616c69646174696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SamsonPHP/validation/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2a9d33e39171aeed84ebe92d85c36aa033759fc165d4f09500eb2523132a91f8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f53616d736f6e5048502f76616c69646174696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/SamsonPHP/validation/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/25033e34fd5a9df69651a6c2a2206d3785d4af8939af76a655c1cc58b331f206/68747470733a2f2f706f7365722e707567782e6f72672f53616d736f6e5048502f76616c69646174696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/SamsonPHP/validation)[![Stories in Ready](https://camo.githubusercontent.com/afc72e3a95e19c4f052443555d88b88ae2b289a355fd92caf46bb61774f19d74/68747470733a2f2f62616467652e776166666c652e696f2f53616d736f6e5048502f76616c69646174696f6e2e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/SamsonPHP/validation)

\##Documentation Follow [official documentation](http://github.com/SamsonPHP/validation/blob/master/docs/Index.md).

\##Installation You can install this package through Composer: `composer require SamsonPHP/validation`The packages adheres to the SemVer specification, and there will be full backward compatibility between minor versions.

\##Testing `$ vendor/bin/phpunit`

\##Usage example

```
var formValidation = new FormValidate([
    new FieldValidate({
        el: '#product_name',
        insertTo: '.error-wrapper',
        styleList: '*'
    }).required().length(),
    new FieldValidate({
        el: '#product_description',
        insertTo: '.error-wrapper',
        styleList: '*'
    }).required(),
    new FieldValidate({
        el: '#product_usp',
        insertTo: '.error-wrapper',
        styleList: '*'
    }).required()
]);

s('#send-form-button').click(function () {
    return formValidation.validate();
});

```

\##Using FieldValidator Just create instance of FieldValidator class and pass options to it:

```
var productFieldValidator = new FieldValidate({
  el: '#product_name',
  insertTo: '.error-wrapper',
  styleList: '*'
}).required().url()

```

And if you want get result of validation you have to call this method:

```
productFieldValidator.validate(); //=> true|false

```

In this example:

- **el** - \[required\] Selector to field, can be string or s() element
- **insertTo** - Selector to field which can dysplay error message, can be string or s() element
- **styleList** - Prefix whcih will instet to message text(default: '')

But there can be a lot of options:

- **trim** - Need remove prefix and suffix spaces
- **fieldErrorClass** - Class which will be added to field, can be string or array.(default: \['class-error-field-', 'class-error-field'\])

If there is array then first element of it will be prefix to all false passed validators.

For example `['class-error-field-', 'class-error-field']`

Will add such classes to field: &lt;input ... class="class-error-field-required class-error-field-regexp class-error-field"&gt;

- **showErrorBlock** - Show error block or not. Default if **insetTo** element passed then block will show. If you want hide error block then pass false to it
- **insertToType** - Where insert error block(default:**MODE\_INSERT\_TO\_PARENT**):

**MODE\_INSERT\_TO\_DEFAULT** - There no changes with insertTo element

**MODE\_INSERT\_TO\_PARENT** - Find elemnet insert to in parent element of this field

- **showErrorBlockType** - Where output classes(default:**MODE\_SHOW\_ERROR\_BLOCK\_DEFAULT**):

**MODE\_SHOW\_ERROR\_BLOCK\_DEFAULT** - Change classes in field

**MODE\_SHOW\_ERROR\_BLOCK\_PARENT** - Change classes in parent block

\##Crate custom validator There very easy to create new validator. It can be class **validator** or **alias**

For create new validator just create class with **export** and **validate** methods **export** method will return object which will be added to main field object **validate** method which validate field with custom login

Constructor of class can receive field object

There is simple required validator:

```
 /**
 * Required validator
 */
var RequiredValidator = (function () {

    /**
     * Init class
     * @param field
     */
    var constructor = function (field) {

        // Required type default values
        this.id = 'required';
        this.defaultRequiredMessage = 'Field have to be filled';
        this.field = field;
    };

    var self = constructor.prototype;

    /**
     * Export data into field
     */
    self.export = function () {
        var validatorInstance = this;

        return {

            /**
             * Required validation
             * @param errorMessage
             * @returns {FieldValidate}
             */
            required: function (errorMessage) {

                validatorInstance.defaultRequiredMessage = errorMessage || validatorInstance.defaultRequiredMessage;
                this.reservedValidators.push(validatorInstance.id);
                return this;
            }
        }
    };

    /**
     * Validate validator
     */
    self.validate = function () {

        if (this.field._getFieldValue() == '') {
            this.field.addError(this.id, this.defaultRequiredMessage);
            this.field.valid = false;
        } else {
            this.field.removeError(this.id);
            this.field.valid = true;
        }
    };

    return constructor;
})();

```

You need add your validator to register validator array

```
// Register all used validators
this.registerValidator = [
    new RequiredValidator(this)
];

```

**required** method will be added to field instance and can be access as `new FieldValidator(...).required()`and such validator can be added

**And you can use alias validator**

There is when you need override some default values form another class validator and save it as new validator.

For example lets create **url** validator which use regExp validator

```
/**
 * Url regexp validator
 */
var UrlValidator = {

    export: function () {
        return {

            /**
             * Url validation
             * @param errorMessage
             * @returns {FieldValidate}
             */
            url: function (errorMessage) {
                var msg = errorMessage || 'Field should be a url',
                    urlPattern = /^(https?:\/\/)?[\w]*\.[\w\-\&\#\=\/\.?\(\)]*$/;

                this.regExp(urlPattern, msg);
                return this;
            }
        }
    }
};

```

As you can see there is only one methond in object which return new object which will be used for extending

And you have to add to register array this validator as object without creating

```
// Register all used validators
this.registerValidator = [
    new RequiredValidator(this),
    new RegExpValidator(this),
    UrlValidator
];

```

And you can use it as:

`new FieldValidator(...).required().url()`

**But You should not use this validator with regExp**

\##Contributing Feel free to fork and create pull requests at any time.

\##Security If you discover any security related issues, please use this repository issue tracker.

\##License Open Software License ("OSL") v 3.0. Please see License File for more information.

[SamsonOS](http://samsonos.com)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~160 days

Total

2

Last Release

3544d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0be8756efdc8f599b8fe9261bed31570d0f140a3b921f0f891877a9133ad654c?d=identicon)[samsonos](/maintainers/samsonos)

---

Top Contributors

[![rmolodyko](https://avatars.githubusercontent.com/u/4399482?v=4)](https://github.com/rmolodyko "rmolodyko (12 commits)")[![vitalyiegorov](https://avatars.githubusercontent.com/u/586558?v=4)](https://github.com/vitalyiegorov "vitalyiegorov (8 commits)")

---

Tags

validationvalidatevalidate formvalidate field

### Embed Badge

![Health badge](/badges/samsonphp-validation/health.svg)

```
[![Health](https://phpackages.com/badges/samsonphp-validation/health.svg)](https://phpackages.com/packages/samsonphp-validation)
```

###  Alternatives

[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.3M29](/packages/wixel-gump)[inhere/php-validate

generic data validate, filter library of the php

26787.4k13](/packages/inhere-php-validate)[sadegh19b/laravel-persian-validation

A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers

18293.8k1](/packages/sadegh19b-laravel-persian-validation)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65378.4k9](/packages/awurth-slim-validation)[bartosz-maciaszek/validation

Validation library for PHP 5.6+ / HHVM inspired by Joi.

3223.3k](/packages/bartosz-maciaszek-validation)[czim/laravel-dataobject

Basic validatable standardized data object.

11137.7k7](/packages/czim-laravel-dataobject)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
