Skip to content

Extra parsley validation rules that translate well to laravel's own validation rules

License

Notifications You must be signed in to change notification settings

happyDemon/ParsleyJS-LaraExtras

Repository files navigation

ParsleyJS-LaraExtras

npm npm GitHub commits

These are extra parsley validation rules that translate well to laravel's own validation rules.

Be sure to take a look at the examples included in the repo.

The documentation is also quite handy.

Install

NPM

npm install parsley-laravel-extras

Next you can import or require it in your js:

require('parsley-laravel-extras')

import 'parsley-laravel-extras'

Or just include dist/laravel-parsley.js right after where you've included parsley.js.

Note Don't forget to include moment.js if you're using date validation.

Note If you'd like support for < IE9, include es5-shim.

Dates

Several date validation rules make use of a config option. This option let's you decide what formats are valid.

By default it looks for the following formats (in order):

window.Parsley.options.dateFormats = ['DD/MM/YY', 'DD/MM/YYYY', 'MM/DD/YY', 'MM/DD/YYYY', 'YY/MM/DD', 'YYYY/MM/DD'];

MomentJS does this strictly, meaning separators are also taken into account.

You can set your valid date formats the same way (this means that all parsley instances will get this assigned by default).

Or you can set it on your parsley instance:

$('form').parsley({
  dateFormats: ['DD-MM-YY', 'DD-MM-YYYY', 'MM-DD-YY', 'MM-DD-YYYY', 'YY-MM-DD', 'YYYY-MM-DD']
});

laravel-parsley.js

Most rules have been included. However I won't tag this repo as a 1.0 release untill I figure out a way to also emulate the way laravel validates arrays.

Rules

Here's an overview of all the Laravel rules and how they can be implemented.

All the linked rules can be used through this library, the textual rules are in Parsley by default.

Laravel Parsley
accepted
active_url
after:date DateAfter
alpha pattern="^[a-zA-Z]+$"
alpha_dash pattern="^[a-zA-Z_-]+$"
alpha_num type="alphanum"
array
before:date DateBefore
between:min,max FileSizeBetween
Between
boolean
confirmed equalTo
date Date
date_format:format DateFormat
different:field Different
digits:value SizeNumber
digits_between:min,max Between
dimensions Dimensions
distinct Distinct
email type="email"
exists:table,column remote
file
filled required
image Image
in:foo,bar,... In
in_array:anotherfield InArray
integer type="integer"
ip
json
max:value fileSizeMax
max(number)
mimetypes:text/plain,... Mimetypes
mimes:foo,bar,... FileExt
min:value fileSizeMin
min (number)
not_in:foo,bar,... NotIn
numeric type="digits"
present
regex:pattern pattern
required required
required_if:anotherfield,value,... RequiredIf
required_unless:anotherfield,value,... RequiredUnless
required_with:foo,bar,... RequiredWith
required_with_all:foo,bar,... RequiredWithAll
required_without:foo,bar,... RequiredWithout
required_without_all:foo,bar,... RequiredWithoutAll
same:field equalto
size:value fileSize
SizeNumber
SizeString
string
timezone
unique:table,column,except,idColumn remote
url type="url"

About

Extra parsley validation rules that translate well to laravel's own validation rules

Resources

License

Stars

Watchers

Forks

Packages

No packages published