Skip to content

Commit b3b67ab

Browse files
committed
New alpha_space custom validation
1 parent 0f00593 commit b3b67ab

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

app/lang/en/validation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"unique" => "The :attribute has already been taken.",
6565
"url" => "The :attribute format is invalid.",
6666

67+
6768
/*
6869
|--------------------------------------------------------------------------
6970
| Custom Validation Language Lines
@@ -76,6 +77,7 @@
7677
*/
7778

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

8082
/*
8183
|--------------------------------------------------------------------------

app/models/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Asset extends Elegant {
55
protected $table = 'assets';
66
protected $softDelete = true;
77
protected $rules = array(
8-
'name' => 'required|min:3',
8+
'name' => 'required|alpha_space|min:3',
99
'asset_tag' => 'required|min:3|unique:assets',
1010
'model_id' => 'required',
1111
'serial' => 'required|alpha_dash|min:3',

app/start/global.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@
9696
*/
9797

9898
require app_path().'/filters.php';
99+
require app_path().'/validators.php';

app/validators.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
Validator::extend('alpha_space', function($attribute,$value,$parameters)
4+
{
5+
return preg_match("/^[-_,. a-zA-Z0-9]+$/",$value);
6+
});

0 commit comments

Comments
 (0)