(Laravel) How to add errors in custom validators?

Dieter91

I followed this short tutorial: http://blog.elenakolevska.com/laravel-alpha-validator-that-allows-spaces/.

Now my question is, how can i add errors to it? Because now i just get this as an error:

validation.alpha_spaces

I'm also curious on how to add numbers to the validator? Thanks!

Edit:

If you don't want to open the link, this is basicly my code:

Validator::extend('alpha_spaces', function($attribute, $value) {
    return preg_match('/^[\pL\s]+$/u', $value);
});
The Alpha

You need to pass a custom error message as well, for example:

Validator::extend('alpha_spaces', function($attribute, $value) {
    // ...
});

Now prepare a message for this custom rule:

$messages = array('alpha_spaces' => 'Your custom error message for :attribute');

Use it like this (with $messages):

$validator = Validator::make($input, $rules, $messages);

Here :attribute will be replace with the form's field name.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I add custom validators in JOI 17?

From Dev

ServiceStack Map Errors in ResponseStatus to custom Errors without Validators

From Dev

How to add Validators in Vaadin 8?

From Dev

How to add validators to a formModel in angular reactive forms

From Dev

How to add composeAsync to angular 5 validators

From Dev

How to add active record validation errors inside custom setter?

From Dev

How to add custom css to blank/errors fields in jQuery validation plugin?

From Dev

Laravel how to add a custom function in an Eloquent model?

From Dev

How to add custom validation rule into laravel 5.2?

From Dev

Laravel 5 - How to add custom msgs to Validation?

From Dev

How to make Laravel 'confirmed' validator to add errors to the confirmation field?

From Dev

How do I add my message to the $errors variable in Laravel 4.2

From Dev

Errors in custom authentication in laravel 5.2

From Dev

How to detect custom errors

From Dev

Spring MockMVC - How to mock custom validators running outside of controllers

From Dev

Spring MockMVC - How to mock custom validators running outside of controllers

From Dev

Testing custom validators with Minitest

From Dev

CausesValidation not working with custom validators

From Dev

Spring MVC custom validators

From Dev

Django Custom Validators Not Working

From Dev

Proptypes custom validators with Flow

From Dev

Getting two errors using Parsley.js to add validators to fields that are dynamically cloned

From Dev

How to add multiple pattern-based validators with parsley.js?

From Dev

How to add validators for @Html.TextBox() without model

From Dev

The Validators And Errors Are Not Working In Angular 9

From Dev

add independent validators to controls

From Dev

RxKotlin: trying to add custom errors catching

From Dev

How do I add a custom field to a model in Laravel?

From Dev

How to add custom config file to app/config in Laravel 5?

Related Related

  1. 1

    How do I add custom validators in JOI 17?

  2. 2

    ServiceStack Map Errors in ResponseStatus to custom Errors without Validators

  3. 3

    How to add Validators in Vaadin 8?

  4. 4

    How to add validators to a formModel in angular reactive forms

  5. 5

    How to add composeAsync to angular 5 validators

  6. 6

    How to add active record validation errors inside custom setter?

  7. 7

    How to add custom css to blank/errors fields in jQuery validation plugin?

  8. 8

    Laravel how to add a custom function in an Eloquent model?

  9. 9

    How to add custom validation rule into laravel 5.2?

  10. 10

    Laravel 5 - How to add custom msgs to Validation?

  11. 11

    How to make Laravel 'confirmed' validator to add errors to the confirmation field?

  12. 12

    How do I add my message to the $errors variable in Laravel 4.2

  13. 13

    Errors in custom authentication in laravel 5.2

  14. 14

    How to detect custom errors

  15. 15

    Spring MockMVC - How to mock custom validators running outside of controllers

  16. 16

    Spring MockMVC - How to mock custom validators running outside of controllers

  17. 17

    Testing custom validators with Minitest

  18. 18

    CausesValidation not working with custom validators

  19. 19

    Spring MVC custom validators

  20. 20

    Django Custom Validators Not Working

  21. 21

    Proptypes custom validators with Flow

  22. 22

    Getting two errors using Parsley.js to add validators to fields that are dynamically cloned

  23. 23

    How to add multiple pattern-based validators with parsley.js?

  24. 24

    How to add validators for @Html.TextBox() without model

  25. 25

    The Validators And Errors Are Not Working In Angular 9

  26. 26

    add independent validators to controls

  27. 27

    RxKotlin: trying to add custom errors catching

  28. 28

    How do I add a custom field to a model in Laravel?

  29. 29

    How to add custom config file to app/config in Laravel 5?

HotTag

Archive