Validate form field in request from laravel

2

How can I validate that a field of the form only allows text ?, that is, do not accept a number or other characters other than normal letters of the alphabet.

I assumed that this would be enough

"campo" => "required|string"

but if I enter the number 1 it allows recording in the database

    
asked by Santiago Muñoz 16.03.2017 в 14:18
source

2 answers

3

With validation string supports Strings and "1" is it.

Put alpha to make sure it's an alpha text betico:

"campo" => "required|alpha"
    
answered by 16.03.2017 / 14:23
source
1

Why wait to go to the backend to validate it, if you can validate from the input with html5 in the following way:

 <input type="text"  pattern="^[a-z]{20}" title="solo acepto letras">

[a-z] here you indicate that you only accept letters from a to z in lowercase.

{20} here you indicate that you accept 20 characters.

    
answered by 17.03.2017 в 12:48