Skip to content
Keeper of regular expressions.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests/regexp
.gitignore
.travis.yml
LICENSE.md
README.md
composer.json

README.md

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]*)'
You can’t perform that action at this time.