Skip to content

Instantly share code, notes, and snippets.

@hassanjamal
Forked from waleedrehmankhan/Validator.php
Created January 26, 2018 16:57
Show Gist options
  • Save hassanjamal/75da8213218798edc78196457397ed40 to your computer and use it in GitHub Desktop.
Save hassanjamal/75da8213218798edc78196457397ed40 to your computer and use it in GitHub Desktop.
Custom Laravel Alphanumeric Validator that allow spaces
Paste this Code in Validator.php
public function validateAlphaSpaces($attribute, $value, $params)
{
return preg_match('/^[\pL\s]+$/u', $value);
}
Create Custom Message some where at bottom in Validation.php
/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap attribute place-holders
| with something more reader friendly such as E-Mail Address instead
| of "email". This simply helps us make messages a little cleaner.
|
*/
"alpha_spaces" => "The :attribute may only contain letters and spaces.",
and call it as usual
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'applicantName' => 'required|alpha_spaces',
];
}
Its Done. :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment