Created
August 18, 2014 12:34
-
-
Save twmbx/69bb4219a1dae611eff8 to your computer and use it in GitHub Desktop.
Additional validators for use with Laravel 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this file is meant for use with laravel 4 | |
// it can be placed in the root of the app directory | |
// and included from routes.php | |
// validate alphabetical chars & spaces only | |
Validator::extend('alpha_space', function($attr, $value) { | |
return preg_match('/^([a-zA-Z ])+$/i', $value); | |
}); | |
// validate alphabetical chars, numbers & spaces only | |
Validator::extend('alpha_num_space', function($attr, $value) { | |
return preg_match('/^([a-zA-Z0-9 ])+$/i', $value); | |
}); | |
// validate alphabetical chars, dashes & spaces only | |
Validator::extend('alpha_dash_space', function($attr, $value) { | |
return preg_match('/^([a-zA-Z -])+$/i', $value); | |
}); | |
// validate alpha, num, dash, underscore | |
Validator::extend('ands', function($attr, $value) { | |
return preg_match('/^[a-zA-Z0-9_-]+$/', $value); | |
}); | |
// validate alpha, num, dash, space | |
Validator::extend('andu', function($attr, $value) { | |
return preg_match('/^[a-zA-Z0-9 -]+$/', $value); | |
}); | |
// validate alpha, num, dash, space, underscore | |
Validator::extend('andsu', function($attr, $value) { | |
return preg_match('/^[a-zA-Z0-9_ -]+$/', $value); | |
}); | |
// assert a maximum number of fields allowed | |
// from a multiple select form control | |
Validator::extend('array_max_count', function($attr, $value, $params) { | |
return count($value) <= $params[0]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment