Componette

Componette

ldrahnik

ldrahnik / regexp v1.3

Keeper of regular expressions.

download-cloud-line composer require ldrahnik/regexp

ldrahnik/regexp

Build Status Latest stable Downloads total

Set of regular expressions.

Requirements

ldrahnik/regexp requires PHP 5.4 or higher.

Installation

Install regexp to your project using Composer:

$ composer require ldrahnik/regexp

Usage

Register extension in config file

extensions:
	regexp: regexp\DI\RegexpHelperExtension

regexp:
	myRegularName: ^[0-9]{1,10}$
	twitterUsername: foo

Now you can use all regulars through services

	/** @var \regexp\Regexp @inject */
	private $regexp;

    public function __construct(regexp\Regexp $regexp)
    {
    	$this->regexp = $regexp;
    }
    
    public function createComponentForm()
    {
        $form = new Nette\Application\UI\Form();
        $form->addText('twitter', 'Twitter username')
            ->setDefaultValue('@')
            ->addCondition(Form::FILLED)
        	    ->addRule(Form::PATTERN, 'Please enter twitter username, for example: @username',
        	    $this->regexp->getTwitterUsername());
        ...

        //  $this->regexp->getRegularExpression('twitterUsername'));
        //  equivalent of that expression is
        //  $this->regexp->getTwitterUsername();
    }
    
    ....

You are able to use or override already existing embedded regular expressions

'username' => '^[a-z0-9_-]{3,16}$',
'twitterUsername' =>  '^(\@)?[A-Za-z0-9_]+$',
'password' => '^[a-z0-9_-]{6,18}$',
'facebook' => '^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]',
'google' => '((http|https):\/\/)?(www[.])?plus\.google\.com\/.?\/?.?\/?([0-9]*)'
  • v1.3

  • v1.2

    Changelog highlights:

    • added option to get regular expression via magic getter
  • v1.1

    Changelog highlights:

    • decreased min version of nette to 2.0
  • v1.0

    Changelog highlights:

    • refactored to extension, now is possible add own regular expressions via config
  • v0.9

    Changelog highlights:

    • added the most frequently used regular expressions and validator messages
price-tag-2-line

Badges

guide-fill

Dependencies

php (>= 5.4)
Componette Componette felix@nette.org