تقریبا تونستم درستش کنم
یه فایل با نام yii.validation.externals.js ساختم با این محتوا
/**
* Yii validation module.
*
* This JavaScript module provides the validation methods for the built-in validators.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @author Mojtaba Baghban <mojtaba.baghban@gmail.com>
* @since 2.0
*/
yii.validation.externals = (function ($) {
var isEmpty = function (value, trim) {
return value === null || value === undefined || value == []
|| value === '' || trim && $.trim(value) === '';
};
var addMessage = function (messages, message, value) {
messages.push(message.replace(/\{value\}/g, value));
};
return {
persianAlpha: function (value, messages, options) {
if (options.skipOnEmpty && isEmpty(value)) {
return;
}
if (!value.match(options.pattern)) {
addMessage(messages, options.message, value);
return;
}
if (options.min !== undefined && value.length < options.min) {
addMessage(messages, options.tooShort, value);
}
if (options.max !== undefined && value.length > options.max) {
addMessage(messages, options.tooLong, value);
}
if (options.is !== undefined && value.length != options.is) {
addMessage(messages, options.is, value);
}
},
nationalCode: function (value, messages, options) {
if (options.skipOnEmpty && isEmpty(value)) {
return;
}
if (!value.match(options.pattern)) {
addMessage(messages, options.message, value);
return;
}
if (value == '0000000000' || value == '1111111111' || value == '2222222222' ||
value == '3333333333' || value == '4444444444' || value == '5555555555' ||
value == '6666666666' || value == '7777777777' || value == '8888888888' ||
value == '9999999999') {
addMessage(messages, options.message, value);
return;
}
var a;
var b = 0;
var c;
var counter = 1;
var check = true;
a = parseInt(value.substring(9, 10));
while (counter <= 9) {
b = b + parseInt(value.substring(counter - 1, counter)) * (11 - counter);
counter = counter + 1;
}
c = b % 11;
if ((c == 0 || c == 1) && a != c) {
addMessage(messages, options.message, value);
return;
}
if (c > 1 && a != 11 - c) {
addMessage(messages, options.message, value);
}
},
phoneNumber: function (value, messages, options) {
if (options.skipOnEmpty && isEmpty(value)) {
return;
}
if (!value.match(options.pattern)) {
addMessage(messages, options.message, value);
return;
}
if (value.length !== options.length) {
addMessage(messages, options.message, value);
}
}
};
})(jQuery);
و واسه اعتبار سنجی مثلا شماره تلفن از yii.validation.externals.phoneNumber استفاده میکنم.
البته ناگفته نماند که از yii2 استفاده میکنم
اگه کسی ایده بهتری داره استقبال میکنم