-
-
Save kvn1234/0ebbe320af1b2d44de271b2c59b7d500 to your computer and use it in GitHub Desktop.
Custom Laravel Alphanumeric Validator that allow spaces
This file contains hidden or 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
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