On form submit, i remove the ‘-’ symbol from the value because i want only numbers.
My problem is client validation include the ‘-’ symbol for counting length for the value. So it wont pass validation. I dont want to change rules to
[['noic'], 'string', 'max' => 12, 'min' => 12]
because the validation message then will prompt that the value should has 14 character because user alredy familiar with this field to has fix 12 character. The ‘-’ symbol is use only for separator, not part of the value.
So how to make client validation doesnt count the ‘-’ symbol?
the client validation still fail for having input more than 12 character.
I want the client validation to validate the input max length as 12 character by counting only number and ignore the ‘-’ character.
Currently i disable client validation and when form submited, in the controller, i remove the ‘-’ character manually so server side validation will success.
I’m asking for solution so i can enable client validation again.
Save data is not a problem. I know how to manipulate data on server side to allow that. My problem is to has proper client side validation with masked input like that. Also, i has no experties about scenarios, maybe i will check it later to properly understand your suggestion.
Hi, thanks for replying. Yeah, sometime ago, i thought i just give up to make it count as 12 and just set as 14. But there is another problem with my masked input. The masked i use create this default input value --. So if the user doesnt complete fill in the input field, for example the user type 1234, the input will be 1234__-__-____, the client validation will see the input has 14 length because it count the _ character as well. So the input value is considered pass client validation.
So in the end, i need to remove the _ character. Now i use the filter validator to remove - and _ character on server, but it doenst automatically do the same for client validation.
Are you using a pattern validation as in my previous code? If I understood, you need to validate not only the length but if all characters are numbers too.
[...]
// you need to adjust for your case...
['cep', 'match', 'pattern' => '/^(\d{2}\.\d{3}-\d{3})$/'],
[...]
In this way the client script will be auto generated and partial input will not pass the validation.