Getting Started

Overview of Mystique and using validators

Note: Mystique provides validators for several languages. However, to use the library you only need to be familiar with the language you intend to use.

Php

With composer (recommended)

Add the following to your root composer.json:

"require": [
    "zoopcommerce/mystique-php": "~1.2"
]

Javascript

Standalone

This is the simplest and fastest way to get started with Javascript. It is one single mimified Javascript file.

Download mystique.js

Full sources with composer

Add the following to your root composer.json:

"require": [
    "zoopcommerce/mystique-js": "~1.2"
],
"extra": {"zoop-js-path": "public/js"}

This will install the mystique sources in your vendor directory, and symlink them to public/js.

Full sources manual install

git clone http://github.com/zoopcommerce/mystique-js mystique
git clone http://github.com/zoopcommerce/mystique mystique-common

Mystique is a shape shifting validation library. It lets you use validators in lots of different places, and in lots of different ways.

Docs sections

Javascript

Detailed information about how to use the validators in a javascript context.

PHP

Detailed information about how to use the validators in a php context.

Validators

Reference for all the validators that come bundled with Mystique.

Spec

Specifications and conventions for the core Base, Result and Chain objects in any language.

Extend

How to build, extend and refine Mystique to fit neatly into your own project.

Bundled Validators

Use the many validators already bundled with mystique.

This example will check if myValue contains only alpha characters, and display a message if it does not.

require(['mystique/Alpha'], function(Alpha){
    var validator = new Alpha,
        result = validator.isValid(myValue);

    if (!result.get('value')){
        alert(result.get('messages').join(' ');
    }
})
var validator = new mystique.Alpha,
    result = validator.isValid(myValue);

if (!result.get('value')){
    alert(result.get('messages').join(' ');
}
$validator = new Zoop\Mystique\Alpha;
$result = $validator->isValid($myValue);

if (!$result->getValue()){
    echo implode(' ', $result->getMessages());
}

Chains

Create complex validators by chaining simpler ones together.

This example will create a validator chain that first checks for alpha characters, and then checks string length.

require(['mystique/Alpha', 'mystique/Length', 'mystique/Chain'], function(Alpha, Length, Chain){
    var validator = new Chain({'validators': [
            new Alpha,
            new Length({'min': 5, 'max': 10})
        ]}),
        result = validator.isValid(myValue);
})
var validator = new mystique.Chain({'validators': [
        new mystique.Alpha,
        new mystique.Length({'min': 5, 'max': 10})
    ]}),
    result = validator.isValid(myValue);
$validator = new Zoop\Mystique\Chain(['validators' => [
    new Zoop\Mystique\Alpha,
    new Zoop\Mystique\Length('min' => 5, 'max' => 10)
]]);
$result = $validator->isValid($myValue);

Dive into the docs for detailed instructions...