PHPackages                             bllim/laravel-to-jquery-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. bllim/laravel-to-jquery-validation

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

bllim/laravel-to-jquery-validation
==================================

This package makes validation rules defined in laravel work client-side by converting to jquery validation rules. It uses Jquery Validation Plugin. It also allows to use laravel validation messages so you can show same messages for both sides.

1.0.1(11y ago)283.1k↓100%6[1 issues](https://github.com/bllim/laravel-to-jquery-validation/issues)MITPHPPHP &gt;=5.3.0

Since Nov 4Pushed 11y ago4 watchersCompare

[ Source](https://github.com/bllim/laravel-to-jquery-validation)[ Packagist](https://packagist.org/packages/bllim/laravel-to-jquery-validation)[ RSS](/packages/bllim-laravel-to-jquery-validation/feed)WikiDiscussions master Synced 1mo ago

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

### This package is no more maintained.

[](#this-package-is-no-more-maintained)

### Look [Laravalid](https://github.com/bllim/laravalid) for same function and more features:

[](#look-laravalid-for-same-function-and-more-features)

- Laravel 4 and Laravel 5 support
- Multi plugin support
- Extendible
- Remote rules support etc.

---

Laravel to Jquery Validation
----------------------------

[](#laravel-to-jquery-validation)

**About**

This package makes validation rules defined in laravel work client-side by converting to jquery validation rules. It uses [Jquery Validation Plugin](http://jqueryvalidation.org/). It also allows to use laravel validation messages so you can show same messages for both sides.

### Feature Overview

[](#feature-overview)

- Converts validation rules from laravel to jquery validator
- Works with laravel form builder
- Can be set validation rule from controller
- Can distinguish between numeric input and string input
- Supports user friendly input names

### Installation

[](#installation)

Require `bllim/laravel-to-jquery-validation` in composer.json and run `composer update`.

```
{
    "require": {
        "laravel/framework": "4.0.*",
        ...
        "bllim/laravel-to-jquery-validation": "*"
    }
    ...
}

```

Composer will download the package. After the package is downloaded, open `app/config/app.php` and add the service provider and alias as below:

```
    'providers' => array(
        ...
        'Bllim\LaravelToJqueryValidation\LaravelToJqueryValidationServiceProvider',
    ),
```

Also you need to publish configuration file and assets by running the following Artisan commands.

```
$ php artisan config:publish bllim/laravel-to-jquery-validation
$ php artisan asset:publish bllim/laravel-to-jquery-validation
```

### Usage

[](#usage)

Since the package uses [Jquery Validation Plugin](http://jqueryvalidation.org/) you should include it in (and include [jquery](http://jquery.com/) of course) your views. Also for unsupported rules in jquery validator, you should include jquery.validate.laravel.js in your views, too. After assets published, they will be copied to your public folder. The last thing you should do at client side is initializing jquery validator plugin as below:

```

$('form').validate();

```

The package uses laravel Form Builder to make validation rules work for both sides. Therefore you should use Form Builder. While opening form by using Form::open you can give $rules as second parameter:

```
    $rules = ['name' => 'required|max:100', 'email' => 'required|email', 'birthdate' => 'date'];
    Form::open(array('url' => 'foo/bar', 'method' => 'put'), $rules);
    Form::text('name');
    Form::text('email');
    Form::text('birthdate');
    Form::close(); // don't forget to close form, it reset validation rules
```

Also if you don't want to struggle with $rules at view files, you can set it in Controller or route by using Form::setValidation . This sets rules for first Form::open

```
    // in controller or route
    $rules = ['name' => 'required|max:100', 'email' => 'required|email', 'birthdate' => 'date'];
    Form::setValidation($rules);

    // in view
    Form::open(array('url' => 'foo/bar', 'method' => 'put'), $rules);
    // some form inputs
    Form::close();
```

For rules which is related to input type in laravel (such as max, min), the package looks for other given rules to understand which type is input. If you give integer or numeric as rule with max, min rules, the package assume input is numeric and convert to data-rule-max instead of data-rule-maxlength.

```
    $rules = ['age' => 'numeric|max'];
```

The converter assume input is string by default. File type is not supported yet.

**Validation Messages**

Converter uses validation messages of laravel (app/lang/en/validation.php) by default for client-side too. If you want to use jquery validation messages, you can set useLaravelMessages, false in config file of package which you copied to your config dir. By default, it is true.

### Example

[](#example)

Controller/Route side

```
class UserController extends Controller {

    public static $createValidation = ['name' => 'required|max:255', 'username' => 'required|regex:/^[a-z\-]*$/|max:20', 'email' => 'required|email', 'age' => 'numeric'];
    public static $createColumns = ['name', 'username', 'email', 'age'];

    public function getCreate()
    {
        Form::setValidation(static::$createValidation);
        return View::make('user.create');
    }

    public function postCreate()
    {
        $inputs = Input::only(static::$createColumns);
        $rules = static::$createValidation;

        $validator = Validator::make($inputs, $rules);

        if($validator->fails())
        {
            // actually withErrors is not really neccessary because we already show errors at client side for normal users
            return Redirect::back()->withErrors($validator);
        }

        // try to create user

        return Redirect::back()->with('success', 'User is created successfully');
    }
}
```

View side

```
DOCTYPE html>

      Laravel to Jquery Validation

        {{ Form::open(array('url'=>'create', 'method'=>'post')) }}
        {{ Form::text('name') }}
        {{ Form::text('username') }}
        {{ Form::email('email') }}
        {{ Form::number('age') }}
        {{ Form::close() }}

        $('form').validate_popover({

            highlight: function(element) {
              jQuery(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function(element) {
              jQuery(element).closest('.form-group').removeClass('has-error');
            },
            events   : 'submit',
            selector : 'input[type!=submit], select, textarea',
            callback : function( elem, valid ) {
                if ( ! valid ) {
                    $( elem ).addClass('error');
                }
            }
          });

```

### Supported validation rules

[](#supported-validation-rules)

- Required
- Email
- URL
- Integer
- Numeric
- IP
- Same
- Regex
- Alpha
- Alphanum
- Image
- Date
- Min
- Max
- Between

### Contribute

[](#contribute)

You can fork and contribute to development of the package. All pull requests is welcome.

**Setting New Convertion Rule**

The package, converts rules by using defined methods which is named like \_convertRuleRuleName and converts messages by using defined methods which is named like \_convertMessageRuleName. You can add new methods to convert current rules and messages. You don't have to add method for converting messages if it is working well without adding. There is getErrorMessage method to handle error messages (which contains just :attribute parameter) by default.

Both rule and message converter method take 3 parameters which are:

```
$parsedRule: ['name' => '', 'parameters' => []] formatted array which gives name and parameters of the rule,
$attribute: attribute name of the input,
$type: type of the current input. by default it is string, if rules of an input contains numeric or integer, it is set numeric.

```

Both rule and message converter returns attributes for the current input. For example if you are converting required rule, you should add input tag `data-rule-requried="true"` by returning `['data-rule-required'=>'true']`

You can look at existed methods to understand how it works.

### Known issues

[](#known-issues)

- Some rules are not supported for now

### TODO

[](#todo)

- Test script
- Support unsupported rules

### License

[](#license)

Licensed under the MIT License

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~114 days

Total

2

Last Release

4092d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c051715d4855bb822e424c43e178349bcc018693a9c025da4042e1c37bed1758?d=identicon)[bgultekin](/maintainers/bgultekin)

---

Top Contributors

[![bllim](https://avatars.githubusercontent.com/u/44695920?v=4)](https://github.com/bllim "bllim (2 commits)")

---

Tags

laravelvalidationjquerylaravel4laravel-validationlaravel validation converterlaravel to jquery validationlaravel validation to jquery validation

### Embed Badge

![Health badge](/badges/bllim-laravel-to-jquery-validation/health.svg)

```
[![Health](https://phpackages.com/badges/bllim-laravel-to-jquery-validation/health.svg)](https://phpackages.com/packages/bllim-laravel-to-jquery-validation)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[bllim/laravalid

This package makes validation rules defined in laravel work client-side by converting to html/js plugins such as jquery validation. It also allows to use laravel validation messages so you can show same messages for both sides.

5915.2k](/packages/bllim-laravalid)

PHPackages © 2026

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