I had similar problem and solved it easily with beforeValidateAttribute
event and this code:
$('#w0').on('beforeValidateAttribute', function (e) {
var paymentAmountElement = $('#w0').yiiActiveForm('find', 'payment-amount');
var oldValidate = paymentAmountElement.validate;
paymentAmountElement.validate = function (attribute, value, messages, deferred, form) {
value = !value.length ? value : value.match(/\d+/g).join('');
oldValidate(attribute, value, messages, deferred, form);
}
});
I had an amount
input in payment
model, so its id is payment-amount
. I saved the original validate function (because I had some others rules like required
and number
and I'm really lazy to writing them again) and remove mask with regular expression, then run original validate function with new value. You just need to make a regular expression for your case and use this approach for solving problem.