Skip to content

Instantly share code, notes, and snippets.

@waleedrehmankhan
Last active January 25, 2023 23:27
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save waleedrehmankhan/89444347f21a549e8c18 to your computer and use it in GitHub Desktop.
Save waleedrehmankhan/89444347f21a549e8c18 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