Validate that a field in yii 2 does not allow writing special characters like,. / - "

0

I want to validate the following in the crud generated by yii 2: - that the user can not write a specific special character such as; or as " He tried to implement it using JavaScript but he does not allow me and in addition to this I have another question: Question 2: how can I make yii2 validate a textfield or textfield, while I am writing, validation is done when I leave the text field or when I click on the form's save data button, but not as I write, then how is it done? .. I am working with just username and password and the code I have is the one that yii2 gives me and the base that I have is the one that migrates when installing yii ..

    
asked by jeanpitx 13.10.2017 в 04:48
source

1 answer

0

Regarding your first question in the validation rules of the form, it would look something like this:

['ejemplo', 'match', "pattern" => "/^[a-záéíóúñ\s;?\"?]+$/i", "message" => "No permitido"],

With the pattern attribute you add what you want to allow, in which case you allow ; and " , in case you delete it only allow lowercase letters.

Regarding your 2 question you can use ajax, although I do not know if at the moment you write it is validating, try to see if it works for you.

    
answered by 22.10.2017 в 22:00