Skip to content

Commit

Permalink
New alpha_space custom validation
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 26, 2013
1 parent 0f00593 commit b3b67ab
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.",


/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
Expand All @@ -76,6 +77,7 @@
*/

'custom' => array(),
'alpha_space' => "The :attribute field may only contain letters, commas, spaces and dashes.",

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Asset extends Elegant {
protected $table = 'assets';
protected $softDelete = true;
protected $rules = array(
'name' => 'required|min:3',
'name' => 'required|alpha_space|min:3',
'asset_tag' => 'required|min:3|unique:assets',
'model_id' => 'required',
'serial' => 'required|alpha_dash|min:3',
Expand Down
1 change: 1 addition & 0 deletions app/start/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@
*/

require app_path().'/filters.php';
require app_path().'/validators.php';
6 changes: 6 additions & 0 deletions app/validators.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

Validator::extend('alpha_space', function($attribute,$value,$parameters)
{
return preg_match("/^[-_,. a-zA-Z0-9]+$/",$value);
});

0 comments on commit b3b67ab

Please sign in to comment.