From 5c8b10ea357a88391d5712e6f87c68159080b934 Mon Sep 17 00:00:00 2001 From: Viktor Shevchenko Date: Sun, 18 Aug 2019 21:42:32 +0300 Subject: [PATCH] Add Digits between rule (#326) * Add digits_between rule * localization for digits_between rule * update dist languages for digits_between rule * comment typo fix --- README.md | 4 +++ dist/lang/ar.js | 1 + dist/lang/ca.js | 1 + dist/lang/da.js | 1 + dist/lang/de.js | 1 + dist/lang/el.js | 1 + dist/lang/en.js | 1 + dist/lang/es.js | 1 + dist/lang/fa.js | 1 + dist/lang/fi.js | 1 + dist/lang/fr.js | 1 + dist/lang/id.js | 1 + dist/lang/it.js | 1 + dist/lang/ja.js | 1 + dist/lang/nb_NO.js | 1 + dist/lang/nl.js | 1 + dist/lang/pl.js | 1 + dist/lang/ro.js | 1 + dist/lang/ru.js | 1 + dist/lang/tr.js | 1 + dist/lang/ua.js | 1 + dist/lang/vi.js | 1 + dist/lang/zh.js | 1 + dist/lang/zh_TW.js | 1 + dist/validator.js | 32 ++++++++++++++++++++- dist/validator.min.js | 2 +- spec/digits_between-rule.js | 56 +++++++++++++++++++++++++++++++++++++ src/attributes.js | 15 ++++++++++ src/lang/ar.js | 1 + src/lang/ca.js | 1 + src/lang/da.js | 1 + src/lang/de.js | 1 + src/lang/el.js | 1 + src/lang/en.js | 1 + src/lang/es.js | 1 + src/lang/fa.js | 1 + src/lang/fi.js | 1 + src/lang/fr.js | 1 + src/lang/id.js | 1 + src/lang/it.js | 1 + src/lang/ja.js | 1 + src/lang/nb_NO.js | 1 + src/lang/nl.js | 1 + src/lang/pl.js | 1 + src/lang/ro.js | 1 + src/lang/ru.js | 1 + src/lang/tr.js | 1 + src/lang/ua.js | 1 + src/lang/vi.js | 1 + src/lang/zh.js | 1 + src/lang/zh_TW.js | 1 + src/rules.js | 14 ++++++++++ 52 files changed, 167 insertions(+), 2 deletions(-) create mode 100755 spec/digits_between-rule.js diff --git a/README.md b/README.md index 617dc690..63566bf5 100755 --- a/README.md +++ b/README.md @@ -223,6 +223,10 @@ The field under validation must be a valid date format which is acceptable by Ja The field under validation must be numeric and must have an exact length of value. +#### digits_between:min,max + +The field under validation must be numeric and must have length between given min and max. + #### different:attribute The given field must be different than the field under validation. diff --git a/dist/lang/ar.js b/dist/lang/ar.js index 1775e9e1..ef9bbca5 100644 --- a/dist/lang/ar.js +++ b/dist/lang/ar.js @@ -14,6 +14,7 @@ module.exports = { date: 'الصفة :attribute صيغتها ليست تاريخ صحيح', def: 'الصفة :attribute تحتوي على أخطاء', digits: 'الصفة :attribute يجب أن تكون :digits أرقام.', + digits_between: 'يجب أن يحتوي :attribute بين :min و :max رقمًا/أرقام .', different: 'الصفة :attribute و الصفة :different يجب أن تكونا مختلفتين', 'in': 'الصفة :attribute المختارة، غير صحيحة.', integer: 'الصفة :attribute يجب أن تكون عدد صحيح', diff --git a/dist/lang/ca.js b/dist/lang/ca.js index 5fb409ab..efd40614 100755 --- a/dist/lang/ca.js +++ b/dist/lang/ca.js @@ -10,6 +10,7 @@ module.exports = { confirmed: 'La confirmació de :attribute no coincideix.', different: 'El camp :attribute y :other poden ser diferents.', digits: 'El camp :attribute pot tindre :digits dígitos.', + digits_between: 'El camp :attribute ha de tenir entre :min i :max dígits.', email: 'El camp :attribute no es un correu válido.', 'in': 'El camp :attribute es invàlid.', integer: 'El camp :attribute pot ser un nombre enter.', diff --git a/dist/lang/da.js b/dist/lang/da.js index fffe9734..903d9539 100755 --- a/dist/lang/da.js +++ b/dist/lang/da.js @@ -14,6 +14,7 @@ module.exports = { date: ':attribute er ikke en gyldig dato.', def: ':attribute attributen har fejl.', digits: ':attribute skal have :digits cifre.', + digits_between: ':attribute skal have mellem :min og :max cifre.', different: ':attribute og :different skal være forskellige.', in: 'Det valgte :attribute er ugyldigt.', integer: ':attribute skal være et heltal.', diff --git a/dist/lang/de.js b/dist/lang/de.js index 9994ec30..808d9777 100755 --- a/dist/lang/de.js +++ b/dist/lang/de.js @@ -14,6 +14,7 @@ module.exports = { date: 'Das :attribute Feld muss ein gültiges Datum sein.', def: 'Das :attribute Feld hat Fehler.', digits: 'Das :attribute Feld muss :digits Stellen haben.', + digits_between: 'Das :attribute Feld muss zwischen :min und :max Stellen haben.', different: 'Die Felder :attribute und :different müssen sich unterscheiden.', 'in': 'Der gewählte Wert für :attribute ist ungültig.', integer: 'Das :attribute Feld muss eine ganze Zahl sein.', diff --git a/dist/lang/el.js b/dist/lang/el.js index 2a2696b2..ead4af94 100755 --- a/dist/lang/el.js +++ b/dist/lang/el.js @@ -11,6 +11,7 @@ module.exports = { date: 'Το πεδίο :attribute δεν είναι έγκυρη ημερομηνία.', def: 'Το πεδίο :attribute περιέχει σφάλματα.', digits: 'Το πεδίο :attribute πρέπει να είναι :digits ψηφία.', + digits_between: 'Το πεδίο :attribute πρέπει να είναι μεταξύ :min και :max ψηφία.', different: 'Το πεδίο :attribute και :different πρέπει να είναι διαφορετικά.', 'in': 'Το επιλεγμένο :attribute δεν είναι έγκυρο.', integer: 'Το πεδίο :attribute πρέπει να είναι ακέραιος.', diff --git a/dist/lang/en.js b/dist/lang/en.js index fed79112..318e1dee 100644 --- a/dist/lang/en.js +++ b/dist/lang/en.js @@ -14,6 +14,7 @@ module.exports = { date: 'The :attribute is not a valid date format.', def: 'The :attribute attribute has errors.', digits: 'The :attribute must be :digits digits.', + digits_between: 'The :attribute field must be between :min and :max digits.', different: 'The :attribute and :different must be different.', 'in': 'The selected :attribute is invalid.', integer: 'The :attribute must be an integer.', diff --git a/dist/lang/es.js b/dist/lang/es.js index 2b25bd8c..5e727362 100755 --- a/dist/lang/es.js +++ b/dist/lang/es.js @@ -10,6 +10,7 @@ module.exports = { confirmed: 'La confirmación de :attribute no coincide.', different: 'El campo :attribute y :other deben ser diferentes.', digits: 'El campo :attribute debe tener :digits dígitos.', + digits_between: 'El campo :attribute debe tener entre :min y :max dígitos.', email: 'El campo :attribute no es un correo válido.', 'in': 'El campo :attribute es inválido.', integer: 'El campo :attribute debe ser un número entero.', diff --git a/dist/lang/fa.js b/dist/lang/fa.js index c68864d2..23d6176c 100755 --- a/dist/lang/fa.js +++ b/dist/lang/fa.js @@ -10,6 +10,7 @@ module.exports = { date: 'تاریخ درج شده در فیلد :attribute صحیح نیست', def: 'فیلد :attribute اشکال دارد', digits: 'فیلد :attribute می بایست شامل :digits رقم باشد', + digits_between: ':attribute باید بین :min و :max رقم باشد.', different: 'فیلد :attribute می بایست مقداری غیر از :different داشته باشد', 'in': 'فیلد :attribute انتخاب شده صحیح نمی باشد', integer: 'فیلد :attribute می بایست عددی باشد', diff --git a/dist/lang/fi.js b/dist/lang/fi.js index 67ebacd3..afc0abe4 100644 --- a/dist/lang/fi.js +++ b/dist/lang/fi.js @@ -14,6 +14,7 @@ module.exports = { date: ':attribute ei ole päivämäärä.', def: ':attribute sisältää virheitä.', digits: ':attribute on oltava :digits numeroa pitkä.', + digits_between: 'Kentän :attribute arvon tulee olla :min - :max numeroa.', different: ':attribute ei saa olla yhtä kuin :different.', 'in': 'Valittu :attribute ei kelpaa.', integer: ':attribute ei ole numero.', diff --git a/dist/lang/fr.js b/dist/lang/fr.js index 03e3d261..d688c526 100755 --- a/dist/lang/fr.js +++ b/dist/lang/fr.js @@ -9,6 +9,7 @@ module.exports = { email: 'Le champ :attribute contient un format invalide.', def: 'Le champ :attribute contient un attribut erroné.', digits: 'Le champ :attribute doit être composé de :digits chiffres.', + digits_between: 'Le champ :attribute doit contenir entre :min et :max chiffres.', different: 'Les champs :attribute et :different doivent être différents.', 'in': 'Le champ :attribute est invalide.', integer: 'Le champ :attribute doit être un entier.', diff --git a/dist/lang/id.js b/dist/lang/id.js index a353c1ba..2b42b923 100644 --- a/dist/lang/id.js +++ b/dist/lang/id.js @@ -14,6 +14,7 @@ module.exports = { date: ':attribute format tanggal tidak benar.', def: ':attribute attribute has errors.', digits: ':attribute harus :digits digit.', + digits_between: 'Isian :attribute harus antara angka :min dan :max.', different: ':attribute dan :different harus berbeda.', 'in': ':attribute tidak benar.', integer: ':attribute harus berupa angka.', diff --git a/dist/lang/it.js b/dist/lang/it.js index c2ecd1cd..2bf0d40d 100755 --- a/dist/lang/it.js +++ b/dist/lang/it.js @@ -9,6 +9,7 @@ module.exports = { email: 'Il formato dell\'attributo :attribute non è valido.', def: 'Gli attributi del campo :attribute contengono degli errori.', digits: 'Il campo :attribute deve essere di :digits cifre.', + digits_between: 'Il campo :attribute deve essere tra :min e :max cifre.', different: 'Il campo :attribute e :different devo essere diversi.', 'in': 'Il valore del campo :attribute non è valido.', integer: 'Il campo :attribute deve essere un valore intero.', diff --git a/dist/lang/ja.js b/dist/lang/ja.js index 5a379121..26f8bebe 100755 --- a/dist/lang/ja.js +++ b/dist/lang/ja.js @@ -14,6 +14,7 @@ module.exports = { date: ':attributeは正しい日付形式を入力してください', def: ':attributeは検証エラーが含まれています。', digits: ':attributeは:digitsの数字のみで入力してください。', + digits_between: ':attributeは、:min桁から:max桁にしてください。', different: ':attributeと:differentは同じであってはなりません。', 'in': '選択された:attributeは無効です。', integer: ':attributeは整数で入力してください。', diff --git a/dist/lang/nb_NO.js b/dist/lang/nb_NO.js index f1666b7f..f52ce1ae 100755 --- a/dist/lang/nb_NO.js +++ b/dist/lang/nb_NO.js @@ -10,6 +10,7 @@ module.exports = { date: ':attribute er et ugyldig datoformat.', def: ':attribute attributtet har feil.', digits: ':attribute må være på :digits siffer.', + digits_between: ':attribute må være mellom :min og :max siffer.', different: ':attribute og :different må være forskjellige.', 'in': 'Den oppgitte verdien for :attribute er ugyldig.', integer: ':attribute må være et heltall.', diff --git a/dist/lang/nl.js b/dist/lang/nl.js index 890d84e0..15b42312 100755 --- a/dist/lang/nl.js +++ b/dist/lang/nl.js @@ -14,6 +14,7 @@ module.exports = { date: 'Het :attribute veld moet een geldige datum zijn.', def: 'Het :attribute veld bevat fouten.', digits: 'Het :attribute veld moet :digits cijfers hebben.', + digits_between: ':attribute moet bestaan uit minimaal :min en maximaal :max cijfers.', different: 'Het :attribute en :different veld moeten verschillend zijn.', 'in': 'De gekozen waarde voor :attribute is ongeldig.', integer: 'Het :attribute veld moet een geheel getal zijn.', diff --git a/dist/lang/pl.js b/dist/lang/pl.js index 835055d9..76607dd2 100755 --- a/dist/lang/pl.js +++ b/dist/lang/pl.js @@ -10,6 +10,7 @@ module.exports = { date: 'Pole :attribute musi mieć poprawny format daty.', def: 'Pole :attribute zawiera błędy.', digits: 'Pole :attribute może zawierać tylko cyfry ze zbioru :digits.', + digits_between: 'Pole :attribute musi mieć od :min do :max cyfr.', different: 'Pola :attribute i :different muszą się różnić.', 'in': 'Pole :attribute musi należeć do zbioru :in.', integer: 'Pole :attribute musi być liczbą całkowitą.', diff --git a/dist/lang/ro.js b/dist/lang/ro.js index 200a7af5..57b89f1f 100644 --- a/dist/lang/ro.js +++ b/dist/lang/ro.js @@ -14,6 +14,7 @@ module.exports = { date: ':attribute nu este un format de dată valid.', def: 'Atributul :attribute are erori.', digits: ':attribute trebuie să aibă :digits cifre.', + digits_between: 'Câmpul :attribute trebuie să aibă între :min și :max cifre.', different: ':attribute și :different trebuie sa fie diferite.', 'in': 'Atributul selectat :attribute nu este valid.', integer: ':attribute trebuie să fie un număr întreg.', diff --git a/dist/lang/ru.js b/dist/lang/ru.js index 9d20ffe2..762bcc3a 100755 --- a/dist/lang/ru.js +++ b/dist/lang/ru.js @@ -9,6 +9,7 @@ module.exports = { email: 'Поле :attribute должно быть действительным электронным адресом.', def: 'Поле :attribute содержит ошибки.', digits: 'Длина цифрового поля :attribute должна быть :digits.', + digits_between: 'Длинна цифрового поля :attribute должна быть от :min до :max знаков.', different: 'Поля :attribute и :different должны различаться.', 'in': 'Выбранное значение для :attribute ошибочно.', integer: 'Поле :attribute должно быть целым числом.', diff --git a/dist/lang/tr.js b/dist/lang/tr.js index 9f5c847f..a50bd6bf 100755 --- a/dist/lang/tr.js +++ b/dist/lang/tr.js @@ -10,6 +10,7 @@ module.exports = { date: ':attribute geöerli bir tarih alanı değil.', def: ':attribute hatalar içeriyor.', digits: ':attribute sadece rakamlardan oluşabilir.', + digits_between: ':attribute :min ile :max arasında rakam olmalıdır.', different: ':attribute ve :different farklı olmalı.', 'in': 'Seçilen :attribute geçerli değil.', integer: ':attribute tam sayı olmalı.', diff --git a/dist/lang/ua.js b/dist/lang/ua.js index 71429c1a..badca12b 100755 --- a/dist/lang/ua.js +++ b/dist/lang/ua.js @@ -9,6 +9,7 @@ module.exports = { email: 'Значення поля :attribute повинно бути існуючою електронною адресою.', def: 'Поле :attribute містить помилки.', digits: 'Довжина числового поля :attribute повинна бути :digits.', + digits_between: 'Довжина цифрового поля :attribute повинна бути від :min до :max.', different: 'Поля :attribute і :different повинні відрізнятись.', 'in': 'Обране значення для :attribute помилкове.', integer: 'Значення поля :attribute повинно бути цілим числом.', diff --git a/dist/lang/vi.js b/dist/lang/vi.js index 7a450cf0..df9d8c7e 100755 --- a/dist/lang/vi.js +++ b/dist/lang/vi.js @@ -10,6 +10,7 @@ module.exports = { date: ':attribute không phải là ngày hợp lệ', def: 'Thuộc tính :attribute có lỗi.', digits: ':attribute phải là số và có chiều dài bằng :digits.', + digits_between: 'Độ dài của trường :attribute phải nằm trong khoảng :min and :max chữ số.', different: 'Giá trị của hai trường :attribute và :different phải khác nhau.', 'in': 'Giá trị được chọn của :attribute không hợp lệ.', integer: ':attribute phải là số nguyên.', diff --git a/dist/lang/zh.js b/dist/lang/zh.js index 6c289bca..611f8c0d 100755 --- a/dist/lang/zh.js +++ b/dist/lang/zh.js @@ -10,6 +10,7 @@ module.exports = { date: ':attribute日期格式错误.', def: ':attribute属性错误.', digits: ':attribute必须是:digits位小数.', + digits_between: ':attribute 必须是介于 :min 和 :max 位的数字。', different: ':attribute和:different必须不同.', 'in': '选择的:attribute无效', integer: ':attribute必须是一个整数.', diff --git a/dist/lang/zh_TW.js b/dist/lang/zh_TW.js index ee13b95f..f0f873fb 100755 --- a/dist/lang/zh_TW.js +++ b/dist/lang/zh_TW.js @@ -10,6 +10,7 @@ module.exports = { date: ':attribute的日期格式錯誤。', def: ':attribute屬性錯誤。', digits: ':attribute必須是:digits位小數。', + digits_between: ':attribute 必須介於 :min 至 :max 位數字。', different: ':attribute和:different必須不同。', 'in': '選擇的:attribute無效', integer: ':attribute必須是一個整數。', diff --git a/dist/validator.js b/dist/validator.js index 611c4c74..5c5c6c02 100644 --- a/dist/validator.js +++ b/dist/validator.js @@ -1,4 +1,4 @@ -/*! validatorjs - v3.15.0 - - 2018-10-26 */ +/*! validatorjs - v3.15.0 - - 2019-03-28 */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Validator = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= min && valueDigitsCount <= max) { + return true; + } + + return false; + }, + regex: function(val, req) { var mod = /[g|i|m]{1,3}$/; var flag = req.match(mod); diff --git a/dist/validator.min.js b/dist/validator.min.js index d78578b2..3a472158 100644 --- a/dist/validator.min.js +++ b/dist/validator.min.js @@ -1 +1 @@ -/*! validatorjs - v3.15.0 - - 2018-10-26 */!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Validator=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0&&c<=6&&(a=a.replace(/\./g,"-"))}var e=new Date(a),f=e.getFullYear(),g=e.getMonth(),h=e.getDate(),i=[31,d(f)?29:28,31,30,31,30,31,31,30,31,30,31];return!(f<1e3)&&(!isNaN(g)&&(!(g+1>12)&&(!isNaN(h)&&(!(h>i[g])&&b))))}function f(a,b,c){this.name=a,this.fn=b,this.passes=null,this._customMessage=void 0,this.async=c}var g,h={required:function(a){var b;return void 0!==a&&null!==a&&(b=String(a).replace(/\s/g,""),b.length>0)},required_if:function(a,b,c){return b=this.getParameters(),this.validator._objectPath(this.validator.input,b[0])!==b[1]||this.validator.getRule("required").validate(a)},required_unless:function(a,b,c){return b=this.getParameters(),this.validator._objectPath(this.validator.input,b[0])===b[1]||this.validator.getRule("required").validate(a)},required_with:function(a,b,c){return!this.validator._objectPath(this.validator.input,b)||this.validator.getRule("required").validate(a)},required_with_all:function(a,b,c){b=this.getParameters();for(var d=0;d=b},max:function(a,b,c){var d=this.getSize();return d<=b},between:function(a,b,c){b=this.getParameters();var d=this.getSize(),e=parseFloat(b[0],10),f=parseFloat(b[1],10);return d>=e&&d<=f},email:function(a){var b=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return b.test(a)},numeric:function(a){var b;return b=Number(a),"number"==typeof b&&!isNaN(b)&&"boolean"!=typeof a},array:function(a){return a instanceof Array},url:function(a){return/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/i.test(a)},alpha:function(a){return/^[a-zA-Z]+$/.test(a)},alpha_dash:function(a){return/^[a-zA-Z0-9_\-]+$/.test(a)},alpha_num:function(a){return/^[a-zA-Z0-9]+$/.test(a)},same:function(a,b){var c=this.validator._flattenObject(this.validator.input)[b],d=a;return c===d},different:function(a,b){var c=this.validator._flattenObject(this.validator.input)[b],d=a;return c!==d},"in":function(a,b){var c,d;if(a&&(c=this.getParameters()),a&&!(a instanceof Array)){var e=a;for(d=0;dnew Date(d).getTime())},before_or_equal:function(a,b){var c=this.validator.input[b],d=a;return!!e(c)&&(!!e(d)&&new Date(c).getTime()>=new Date(d).getTime())},hex:function(a){return/^[0-9a-f]+$/i.test(a)}},i=function(){throw new Error("Validator `"+this.name+"` is not defined!")};f.prototype={validate:function(a,b,c,d){var e=this;if(this._setValidatingData(c,a,b),"function"==typeof d){this.callback=d;var f=function(a,b){e.response(a,b)};return this.async?this._apply(a,b,c,f):f(this._apply(a,b,c))}return this._apply(a,b,c)},_apply:function(a,b,c,d){var e=this.isMissed()?i:this.fn;return e.apply(this,[a,b,c,d])},_setValidatingData:function(a,b,c){this.attribute=a,this.inputValue=b,this.ruleValue=c},getParameters:function(){var a=[];return"string"==typeof this.ruleValue&&(a=this.ruleValue.split(",")),"number"==typeof this.ruleValue&&a.push(this.ruleValue),this.ruleValue instanceof Array&&(a=this.ruleValue),a},getSize:function(){var a=this.inputValue;return a instanceof Array?a.length:"number"==typeof a?a:this.validator._hasNumericRule(this.attribute)?parseFloat(a,10):a.length},_getValueType:function(){return"number"==typeof this.inputValue||this.validator._hasNumericRule(this.attribute)?"numeric":"string"},response:function(a,b){this.passes=void 0===a||a===!0,this._customMessage=b,this.callback(this.passes,b)},setValidator:function(a){this.validator=a},isMissed:function(){return"function"!=typeof this.fn},get customMessage(){return this.isMissed()?g:this._customMessage}};var j={asyncRules:[],implicitRules:["required","required_if","required_unless","required_with","required_with_all","required_without","required_without_all","accepted","present"],make:function(a,b){var c=this.isAsync(a),d=new f(a,h[a],c);return d.setValidator(b),d},isAsync:function(a){for(var b=0,c=this.asyncRules.length;b-1},register:function(a,b){h[a]=b},registerImplicit:function(a,b){this.register(a,b),this.implicitRules.push(a)},registerAsync:function(a,b){this.register(a,b),this.asyncRules.push(a)},registerAsyncImplicit:function(a,b){this.registerImplicit(a,b),this.asyncRules.push(a)},registerMissedRuleValidator:function(a,b){i=a,g=b}};b.exports=j},{}],8:[function(a,b,c){var d=a("./rules"),e=a("./lang"),f=a("./errors"),g=a("./attributes"),h=a("./async"),i=function(a,b,c){var d=i.getDefaultLang();this.input=a||{},this.messages=e._make(d),this.messages._setCustom(c),this.setAttributeFormatter(i.prototype.attributeFormatter),this.errors=new f,this.errorCount=0,this.hasAsync=!1,this.rules=this._parseRules(b)};i.prototype={constructor:i,lang:"en",numericRules:["integer","numeric"],attributeFormatter:g.formatter,check:function(){for(var a in this.rules){var b=this.rules[a],c=this._objectPath(this.input,a);if(!this._hasRule(a,["sometimes"])||this._suppliedWithData(a))for(var d,e,f,g=0,h=b.length;g-1?this._parsedRulesRecurse(a,b,c,d):this._parseRulesDefault(a,b,c,d)},_parsedRulesRecurse:function(a,b,c,d){var e=a.substr(0,a.indexOf("*")-1),f=this._objectPath(this.input,e);if(f)for(var g=0;g=0&&(b=a.split(":"),c.name=b[0],c.value=b.slice(1).join(":")),c},_hasRule:function(a,b){for(var c=this.rules[a]||[],d=0,e=c.length;d-1)return!0;return!1},_hasNumericRule:function(a){return this._hasRule(a,this.numericRules)},_isValidatable:function(a,b){return!!d.isImplicit(a.name)||this.getRule("required").validate(b)},_shouldStopValidating:function(a,b){var c=this.stopOnAttributes;return"undefined"!=typeof c&&c!==!1&&b!==!0&&(!(c instanceof Array)||c.indexOf(a)>-1)},setAttributeNames:function(a){this.messages._setAttributeNames(a)},setAttributeFormatter:function(a){this.messages._setAttributeFormatter(a)},getRule:function(a){return d.make(a,this)},stopOnError:function(a){this.stopOnAttributes=a},passes:function(a){var b=this._checkAsync("passes",a);return b?this.checkAsync(a):this.check()},fails:function(a){var b=this._checkAsync("fails",a);return b?this.checkAsync(function(){},a):!this.check()},_checkAsync:function(a,b){var c="function"==typeof b;if(this.hasAsync&&!c)throw a+" expects a callback when async rules are being tested.";return this.hasAsync||c}},i.setMessages=function(a,b){return e._set(a,b),this},i.getMessages=function(a){return e._get(a)},i.useLang=function(a){this.prototype.lang=a},i.getDefaultLang=function(){return this.prototype.lang},i.setAttributeFormatter=function(a){this.prototype.attributeFormatter=a},i.stopOnError=function(a){this.prototype.stopOnAttributes=a},i.register=function(a,b,c){var f=i.getDefaultLang();d.register(a,b),e._setRuleMessage(f,a,c)},i.registerImplicit=function(a,b,c){var f=i.getDefaultLang();d.registerImplicit(a,b),e._setRuleMessage(f,a,c)},i.registerAsync=function(a,b,c){var f=i.getDefaultLang();d.registerAsync(a,b),e._setRuleMessage(f,a,c)},i.registerAsyncImplicit=function(a,b,c){var f=i.getDefaultLang();d.registerAsyncImplicit(a,b),e._setRuleMessage(f,a,c)},i.registerMissedRuleValidator=function(a,b){d.registerMissedRuleValidator(a,b)},b.exports=i},{"./async":1,"./attributes":2,"./errors":3,"./lang":4,"./rules":7}]},{},[8])(8)}); \ No newline at end of file +/*! validatorjs - v3.15.0 - - 2019-03-28 */!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.Validator=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0&&c<=6&&(a=a.replace(/\./g,"-"))}var e=new Date(a),f=e.getFullYear(),g=e.getMonth(),h=e.getDate(),i=[31,d(f)?29:28,31,30,31,30,31,31,30,31,30,31];return!(f<1e3)&&(!isNaN(g)&&(!(g+1>12)&&(!isNaN(h)&&(!(h>i[g])&&b))))}function f(a,b,c){this.name=a,this.fn=b,this.passes=null,this._customMessage=void 0,this.async=c}var g,h={required:function(a){var b;return void 0!==a&&null!==a&&(b=String(a).replace(/\s/g,""),b.length>0)},required_if:function(a,b,c){return b=this.getParameters(),this.validator._objectPath(this.validator.input,b[0])!==b[1]||this.validator.getRule("required").validate(a)},required_unless:function(a,b,c){return b=this.getParameters(),this.validator._objectPath(this.validator.input,b[0])===b[1]||this.validator.getRule("required").validate(a)},required_with:function(a,b,c){return!this.validator._objectPath(this.validator.input,b)||this.validator.getRule("required").validate(a)},required_with_all:function(a,b,c){b=this.getParameters();for(var d=0;d=b},max:function(a,b,c){var d=this.getSize();return d<=b},between:function(a,b,c){b=this.getParameters();var d=this.getSize(),e=parseFloat(b[0],10),f=parseFloat(b[1],10);return d>=e&&d<=f},email:function(a){var b=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return b.test(a)},numeric:function(a){var b;return b=Number(a),"number"==typeof b&&!isNaN(b)&&"boolean"!=typeof a},array:function(a){return a instanceof Array},url:function(a){return/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/i.test(a)},alpha:function(a){return/^[a-zA-Z]+$/.test(a)},alpha_dash:function(a){return/^[a-zA-Z0-9_\-]+$/.test(a)},alpha_num:function(a){return/^[a-zA-Z0-9]+$/.test(a)},same:function(a,b){var c=this.validator._flattenObject(this.validator.input)[b],d=a;return c===d},different:function(a,b){var c=this.validator._flattenObject(this.validator.input)[b],d=a;return c!==d},"in":function(a,b){var c,d;if(a&&(c=this.getParameters()),a&&!(a instanceof Array)){var e=a;for(d=0;d=e&&d<=f)},regex:function(a,b){var c=/[g|i|m]{1,3}$/,d=b.match(c);return d=d?d[0]:"",b=b.replace(c,"").slice(1,-1),b=new RegExp(b,d),!!b.test(a)},date:function(a,b){return e(a)},present:function(a){return"undefined"!=typeof a},after:function(a,b){var c=this.validator.input[b],d=a;return!!e(c)&&(!!e(d)&&new Date(c).getTime()new Date(d).getTime())},before_or_equal:function(a,b){var c=this.validator.input[b],d=a;return!!e(c)&&(!!e(d)&&new Date(c).getTime()>=new Date(d).getTime())},hex:function(a){return/^[0-9a-f]+$/i.test(a)}},i=function(){throw new Error("Validator `"+this.name+"` is not defined!")};f.prototype={validate:function(a,b,c,d){var e=this;if(this._setValidatingData(c,a,b),"function"==typeof d){this.callback=d;var f=function(a,b){e.response(a,b)};return this.async?this._apply(a,b,c,f):f(this._apply(a,b,c))}return this._apply(a,b,c)},_apply:function(a,b,c,d){var e=this.isMissed()?i:this.fn;return e.apply(this,[a,b,c,d])},_setValidatingData:function(a,b,c){this.attribute=a,this.inputValue=b,this.ruleValue=c},getParameters:function(){var a=[];return"string"==typeof this.ruleValue&&(a=this.ruleValue.split(",")),"number"==typeof this.ruleValue&&a.push(this.ruleValue),this.ruleValue instanceof Array&&(a=this.ruleValue),a},getSize:function(){var a=this.inputValue;return a instanceof Array?a.length:"number"==typeof a?a:this.validator._hasNumericRule(this.attribute)?parseFloat(a,10):a.length},_getValueType:function(){return"number"==typeof this.inputValue||this.validator._hasNumericRule(this.attribute)?"numeric":"string"},response:function(a,b){this.passes=void 0===a||a===!0,this._customMessage=b,this.callback(this.passes,b)},setValidator:function(a){this.validator=a},isMissed:function(){return"function"!=typeof this.fn},get customMessage(){return this.isMissed()?g:this._customMessage}};var j={asyncRules:[],implicitRules:["required","required_if","required_unless","required_with","required_with_all","required_without","required_without_all","accepted","present"],make:function(a,b){var c=this.isAsync(a),d=new f(a,h[a],c);return d.setValidator(b),d},isAsync:function(a){for(var b=0,c=this.asyncRules.length;b-1},register:function(a,b){h[a]=b},registerImplicit:function(a,b){this.register(a,b),this.implicitRules.push(a)},registerAsync:function(a,b){this.register(a,b),this.asyncRules.push(a)},registerAsyncImplicit:function(a,b){this.registerImplicit(a,b),this.asyncRules.push(a)},registerMissedRuleValidator:function(a,b){i=a,g=b}};b.exports=j},{}],8:[function(a,b,c){var d=a("./rules"),e=a("./lang"),f=a("./errors"),g=a("./attributes"),h=a("./async"),i=function(a,b,c){var d=i.getDefaultLang();this.input=a||{},this.messages=e._make(d),this.messages._setCustom(c),this.setAttributeFormatter(i.prototype.attributeFormatter),this.errors=new f,this.errorCount=0,this.hasAsync=!1,this.rules=this._parseRules(b)};i.prototype={constructor:i,lang:"en",numericRules:["integer","numeric"],attributeFormatter:g.formatter,check:function(){for(var a in this.rules){var b=this.rules[a],c=this._objectPath(this.input,a);if(!this._hasRule(a,["sometimes"])||this._suppliedWithData(a))for(var d,e,f,g=0,h=b.length;g-1?this._parsedRulesRecurse(a,b,c,d):this._parseRulesDefault(a,b,c,d)},_parsedRulesRecurse:function(a,b,c,d){var e=a.substr(0,a.indexOf("*")-1),f=this._objectPath(this.input,e);if(f)for(var g=0;g=0&&(b=a.split(":"),c.name=b[0],c.value=b.slice(1).join(":")),c},_hasRule:function(a,b){for(var c=this.rules[a]||[],d=0,e=c.length;d-1)return!0;return!1},_hasNumericRule:function(a){return this._hasRule(a,this.numericRules)},_isValidatable:function(a,b){return!!d.isImplicit(a.name)||this.getRule("required").validate(b)},_shouldStopValidating:function(a,b){var c=this.stopOnAttributes;return"undefined"!=typeof c&&c!==!1&&b!==!0&&(!(c instanceof Array)||c.indexOf(a)>-1)},setAttributeNames:function(a){this.messages._setAttributeNames(a)},setAttributeFormatter:function(a){this.messages._setAttributeFormatter(a)},getRule:function(a){return d.make(a,this)},stopOnError:function(a){this.stopOnAttributes=a},passes:function(a){var b=this._checkAsync("passes",a);return b?this.checkAsync(a):this.check()},fails:function(a){var b=this._checkAsync("fails",a);return b?this.checkAsync(function(){},a):!this.check()},_checkAsync:function(a,b){var c="function"==typeof b;if(this.hasAsync&&!c)throw a+" expects a callback when async rules are being tested.";return this.hasAsync||c}},i.setMessages=function(a,b){return e._set(a,b),this},i.getMessages=function(a){return e._get(a)},i.useLang=function(a){this.prototype.lang=a},i.getDefaultLang=function(){return this.prototype.lang},i.setAttributeFormatter=function(a){this.prototype.attributeFormatter=a},i.stopOnError=function(a){this.prototype.stopOnAttributes=a},i.register=function(a,b,c){var f=i.getDefaultLang();d.register(a,b),e._setRuleMessage(f,a,c)},i.registerImplicit=function(a,b,c){var f=i.getDefaultLang();d.registerImplicit(a,b),e._setRuleMessage(f,a,c)},i.registerAsync=function(a,b,c){var f=i.getDefaultLang();d.registerAsync(a,b),e._setRuleMessage(f,a,c)},i.registerAsyncImplicit=function(a,b,c){var f=i.getDefaultLang();d.registerAsyncImplicit(a,b),e._setRuleMessage(f,a,c)},i.registerMissedRuleValidator=function(a,b){d.registerMissedRuleValidator(a,b)},b.exports=i},{"./async":1,"./attributes":2,"./errors":3,"./lang":4,"./rules":7}]},{},[8])(8)}); \ No newline at end of file diff --git a/spec/digits_between-rule.js b/spec/digits_between-rule.js new file mode 100755 index 00000000..5486a108 --- /dev/null +++ b/spec/digits_between-rule.js @@ -0,0 +1,56 @@ +if (typeof require !== 'undefined') { + var Validator = require('../src/validator.js'); + var expect = require('chai').expect; +} else { + var Validator = window.Validator; + var expect = window.chai.expect; +} + +describe('digits_between rule', function() { + it('should be numeric and must have an exact length between 8 and 10', function() { + var validation = new Validator({ + phone: '800692775' + }, { + phone: 'digits_between:8,10' + }); + + expect(validation.passes()).to.be.true; + expect(validation.fails()).to.be.false; + }); + + it('should not pass if non-digits are present', function() { + var validation = new Validator({ + phone: '80069277a' + }, { + phone: 'digits_between:8,10' + }); + + expect(validation.fails()).to.be.true; + expect(validation.errors.first('phone')).to.equal('The phone field must be between 8 and 10 digits.'); + expect(validation.passes()).to.be.false; + }); + + it('should not pass if value length is below minimum', function() { + var validation = new Validator({ + phone: '8006927' + }, { + phone: 'digits_between:8,10' + }); + + expect(validation.fails()).to.be.true; + expect(validation.errors.first('phone')).to.equal('The phone field must be between 8 and 10 digits.'); + expect(validation.passes()).to.be.false; + }); + + it('should not pass if value length is above maximum', function() { + var validation = new Validator({ + phone: '80069277525' + }, { + phone: 'digits_between:8,10' + }); + + expect(validation.fails()).to.be.true; + expect(validation.errors.first('phone')).to.equal('The phone field must be between 8 and 10 digits.'); + expect(validation.passes()).to.be.false; + }); +}); diff --git a/src/attributes.js b/src/attributes.js index e932cf18..7541aafb 100755 --- a/src/attributes.js +++ b/src/attributes.js @@ -15,6 +15,21 @@ var replacements = { }); }, + /** + * Digits-Between replacement (replaces :min and :max) + * + * @param {string} template + * @param {Rule} rule + * @return {string} + */ + digits_between: function(template, rule) { + var parameters = rule.getParameters(); + return this._replacePlaceholders(rule, template, { + min: parameters[0], + max: parameters[1] + }); + }, + /** * Required_if replacement. * diff --git a/src/lang/ar.js b/src/lang/ar.js index e0b84391..04665d61 100755 --- a/src/lang/ar.js +++ b/src/lang/ar.js @@ -13,6 +13,7 @@ module.exports = { date: 'الصفة :attribute صيغتها ليست تاريخ صحيح', def: 'الصفة :attribute تحتوي على أخطاء', digits: 'الصفة :attribute يجب أن تكون :digits أرقام.', + digits_between: 'يجب أن يحتوي :attribute بين :min و :max رقمًا/أرقام .', different: 'الصفة :attribute و الصفة :different يجب أن تكونا مختلفتين', 'in': 'الصفة :attribute المختارة، غير صحيحة.', integer: 'الصفة :attribute يجب أن تكون عدد صحيح', diff --git a/src/lang/ca.js b/src/lang/ca.js index 272ae63e..5727336f 100755 --- a/src/lang/ca.js +++ b/src/lang/ca.js @@ -9,6 +9,7 @@ module.exports = { confirmed: 'La confirmació de :attribute no coincideix.', different: 'El camp :attribute y :other poden ser diferents.', digits: 'El camp :attribute pot tindre :digits dígitos.', + digits_between: 'El camp :attribute ha de tenir entre :min i :max dígits.', email: 'El camp :attribute no es un correu válido.', 'in': 'El camp :attribute es invàlid.', integer: 'El camp :attribute pot ser un nombre enter.', diff --git a/src/lang/da.js b/src/lang/da.js index de55bbc6..d8fcd41f 100755 --- a/src/lang/da.js +++ b/src/lang/da.js @@ -13,6 +13,7 @@ module.exports = { date: ':attribute er ikke en gyldig dato.', def: ':attribute attributen har fejl.', digits: ':attribute skal have :digits cifre.', + digits_between: ':attribute skal have mellem :min og :max cifre.', different: ':attribute og :different skal være forskellige.', in: 'Det valgte :attribute er ugyldigt.', integer: ':attribute skal være et heltal.', diff --git a/src/lang/de.js b/src/lang/de.js index bd7b934c..c2ed96cc 100755 --- a/src/lang/de.js +++ b/src/lang/de.js @@ -13,6 +13,7 @@ module.exports = { date: 'Das :attribute Feld muss ein gültiges Datum sein.', def: 'Das :attribute Feld hat Fehler.', digits: 'Das :attribute Feld muss :digits Stellen haben.', + digits_between: 'Das :attribute Feld muss zwischen :min und :max Stellen haben.', different: 'Die Felder :attribute und :different müssen sich unterscheiden.', 'in': 'Der gewählte Wert für :attribute ist ungültig.', integer: 'Das :attribute Feld muss eine ganze Zahl sein.', diff --git a/src/lang/el.js b/src/lang/el.js index d31048a3..1a013c5e 100755 --- a/src/lang/el.js +++ b/src/lang/el.js @@ -10,6 +10,7 @@ module.exports = { date: 'Το πεδίο :attribute δεν είναι έγκυρη ημερομηνία.', def: 'Το πεδίο :attribute περιέχει σφάλματα.', digits: 'Το πεδίο :attribute πρέπει να είναι :digits ψηφία.', + digits_between: 'Το πεδίο :attribute πρέπει να είναι μεταξύ :min και :max ψηφία.', different: 'Το πεδίο :attribute και :different πρέπει να είναι διαφορετικά.', 'in': 'Το επιλεγμένο :attribute δεν είναι έγκυρο.', integer: 'Το πεδίο :attribute πρέπει να είναι ακέραιος.', diff --git a/src/lang/en.js b/src/lang/en.js index 97e82879..db8a9663 100755 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -13,6 +13,7 @@ module.exports = { date: 'The :attribute is not a valid date format.', def: 'The :attribute attribute has errors.', digits: 'The :attribute must be :digits digits.', + digits_between: 'The :attribute field must be between :min and :max digits.', different: 'The :attribute and :different must be different.', 'in': 'The selected :attribute is invalid.', integer: 'The :attribute must be an integer.', diff --git a/src/lang/es.js b/src/lang/es.js index 4d6d397b..c29e6efc 100755 --- a/src/lang/es.js +++ b/src/lang/es.js @@ -9,6 +9,7 @@ module.exports = { confirmed: 'La confirmación de :attribute no coincide.', different: 'El campo :attribute y :other deben ser diferentes.', digits: 'El campo :attribute debe tener :digits dígitos.', + digits_between: 'El campo :attribute debe tener entre :min y :max dígitos.', email: 'El campo :attribute no es un correo válido.', 'in': 'El campo :attribute es inválido.', integer: 'El campo :attribute debe ser un número entero.', diff --git a/src/lang/fa.js b/src/lang/fa.js index 37921618..c129c255 100755 --- a/src/lang/fa.js +++ b/src/lang/fa.js @@ -9,6 +9,7 @@ module.exports = { date: 'تاریخ درج شده در فیلد :attribute صحیح نیست', def: 'فیلد :attribute اشکال دارد', digits: 'فیلد :attribute می بایست شامل :digits رقم باشد', + digits_between: ':attribute باید بین :min و :max رقم باشد.', different: 'فیلد :attribute می بایست مقداری غیر از :different داشته باشد', 'in': 'فیلد :attribute انتخاب شده صحیح نمی باشد', integer: 'فیلد :attribute می بایست عددی باشد', diff --git a/src/lang/fi.js b/src/lang/fi.js index dc4c24f9..1025c2d1 100644 --- a/src/lang/fi.js +++ b/src/lang/fi.js @@ -13,6 +13,7 @@ module.exports = { date: ':attribute ei ole päivämäärä.', def: ':attribute sisältää virheitä.', digits: ':attribute on oltava :digits numeroa pitkä.', + digits_between: 'Kentän :attribute arvon tulee olla :min - :max numeroa.', different: ':attribute ei saa olla yhtä kuin :different.', 'in': 'Valittu :attribute ei kelpaa.', integer: ':attribute ei ole numero.', diff --git a/src/lang/fr.js b/src/lang/fr.js index 0e6a0869..2fb58deb 100755 --- a/src/lang/fr.js +++ b/src/lang/fr.js @@ -8,6 +8,7 @@ module.exports = { email: 'Le champ :attribute contient un format invalide.', def: 'Le champ :attribute contient un attribut erroné.', digits: 'Le champ :attribute doit être composé de :digits chiffres.', + digits_between: 'Le champ :attribute doit contenir entre :min et :max chiffres.', different: 'Les champs :attribute et :different doivent être différents.', 'in': 'Le champ :attribute est invalide.', integer: 'Le champ :attribute doit être un entier.', diff --git a/src/lang/id.js b/src/lang/id.js index 48a94a9f..da74ff71 100755 --- a/src/lang/id.js +++ b/src/lang/id.js @@ -13,6 +13,7 @@ module.exports = { date: ':attribute format tanggal tidak benar.', def: ':attribute attribute has errors.', digits: ':attribute harus :digits digit.', + digits_between: 'Isian :attribute harus antara angka :min dan :max.', different: ':attribute dan :different harus berbeda.', 'in': ':attribute tidak benar.', integer: ':attribute harus berupa angka.', diff --git a/src/lang/it.js b/src/lang/it.js index 4c91765a..bd993701 100755 --- a/src/lang/it.js +++ b/src/lang/it.js @@ -8,6 +8,7 @@ module.exports = { email: 'Il formato dell\'attributo :attribute non è valido.', def: 'Gli attributi del campo :attribute contengono degli errori.', digits: 'Il campo :attribute deve essere di :digits cifre.', + digits_between: 'Il campo :attribute deve essere tra :min e :max cifre.', different: 'Il campo :attribute e :different devo essere diversi.', 'in': 'Il valore del campo :attribute non è valido.', integer: 'Il campo :attribute deve essere un valore intero.', diff --git a/src/lang/ja.js b/src/lang/ja.js index 48f6c62a..97ab7010 100755 --- a/src/lang/ja.js +++ b/src/lang/ja.js @@ -13,6 +13,7 @@ module.exports = { date: ':attributeは正しい日付形式を入力してください', def: ':attributeは検証エラーが含まれています。', digits: ':attributeは:digitsの数字のみで入力してください。', + digits_between: ':attributeは、:min桁から:max桁にしてください。', different: ':attributeと:differentは同じであってはなりません。', 'in': '選択された:attributeは無効です。', integer: ':attributeは整数で入力してください。', diff --git a/src/lang/nb_NO.js b/src/lang/nb_NO.js index 22292557..e0b685a8 100755 --- a/src/lang/nb_NO.js +++ b/src/lang/nb_NO.js @@ -9,6 +9,7 @@ module.exports = { date: ':attribute er et ugyldig datoformat.', def: ':attribute attributtet har feil.', digits: ':attribute må være på :digits siffer.', + digits_between: ':attribute må være mellom :min og :max siffer.', different: ':attribute og :different må være forskjellige.', 'in': 'Den oppgitte verdien for :attribute er ugyldig.', integer: ':attribute må være et heltall.', diff --git a/src/lang/nl.js b/src/lang/nl.js index 17c6123b..dda2c17d 100755 --- a/src/lang/nl.js +++ b/src/lang/nl.js @@ -13,6 +13,7 @@ module.exports = { date: 'Het :attribute veld moet een geldige datum zijn.', def: 'Het :attribute veld bevat fouten.', digits: 'Het :attribute veld moet :digits cijfers hebben.', + digits_between: ':attribute moet bestaan uit minimaal :min en maximaal :max cijfers.', different: 'Het :attribute en :different veld moeten verschillend zijn.', 'in': 'De gekozen waarde voor :attribute is ongeldig.', integer: 'Het :attribute veld moet een geheel getal zijn.', diff --git a/src/lang/pl.js b/src/lang/pl.js index d7776937..360b09bb 100755 --- a/src/lang/pl.js +++ b/src/lang/pl.js @@ -9,6 +9,7 @@ module.exports = { date: 'Pole :attribute musi mieć poprawny format daty.', def: 'Pole :attribute zawiera błędy.', digits: 'Pole :attribute może zawierać tylko cyfry ze zbioru :digits.', + digits_between: 'Pole :attribute musi mieć od :min do :max cyfr.', different: 'Pola :attribute i :different muszą się różnić.', 'in': 'Pole :attribute musi należeć do zbioru :in.', integer: 'Pole :attribute musi być liczbą całkowitą.', diff --git a/src/lang/ro.js b/src/lang/ro.js index 5b0493dd..2432fe9d 100644 --- a/src/lang/ro.js +++ b/src/lang/ro.js @@ -13,6 +13,7 @@ module.exports = { date: ':attribute nu este un format de dată valid.', def: 'Atributul :attribute are erori.', digits: ':attribute trebuie să aibă :digits cifre.', + digits_between: 'Câmpul :attribute trebuie să aibă între :min și :max cifre.', different: ':attribute și :different trebuie sa fie diferite.', 'in': 'Atributul selectat :attribute nu este valid.', integer: ':attribute trebuie să fie un număr întreg.', diff --git a/src/lang/ru.js b/src/lang/ru.js index ab9c2954..f183ba64 100755 --- a/src/lang/ru.js +++ b/src/lang/ru.js @@ -8,6 +8,7 @@ module.exports = { email: 'Поле :attribute должно быть действительным электронным адресом.', def: 'Поле :attribute содержит ошибки.', digits: 'Длина цифрового поля :attribute должна быть :digits.', + digits_between: 'Длинна цифрового поля :attribute должна быть от :min до :max знаков.', different: 'Поля :attribute и :different должны различаться.', 'in': 'Выбранное значение для :attribute ошибочно.', integer: 'Поле :attribute должно быть целым числом.', diff --git a/src/lang/tr.js b/src/lang/tr.js index aa9bce76..bf596cc2 100755 --- a/src/lang/tr.js +++ b/src/lang/tr.js @@ -9,6 +9,7 @@ module.exports = { date: ':attribute geöerli bir tarih alanı değil.', def: ':attribute hatalar içeriyor.', digits: ':attribute sadece rakamlardan oluşabilir.', + digits_between: ':attribute :min ile :max arasında rakam olmalıdır.', different: ':attribute ve :different farklı olmalı.', 'in': 'Seçilen :attribute geçerli değil.', integer: ':attribute tam sayı olmalı.', diff --git a/src/lang/ua.js b/src/lang/ua.js index 538f78f0..f38aac39 100755 --- a/src/lang/ua.js +++ b/src/lang/ua.js @@ -8,6 +8,7 @@ module.exports = { email: 'Значення поля :attribute повинно бути існуючою електронною адресою.', def: 'Поле :attribute містить помилки.', digits: 'Довжина числового поля :attribute повинна бути :digits.', + digits_between: 'Довжина цифрового поля :attribute повинна бути від :min до :max.', different: 'Поля :attribute і :different повинні відрізнятись.', 'in': 'Обране значення для :attribute помилкове.', integer: 'Значення поля :attribute повинно бути цілим числом.', diff --git a/src/lang/vi.js b/src/lang/vi.js index c832ae69..191722d1 100755 --- a/src/lang/vi.js +++ b/src/lang/vi.js @@ -9,6 +9,7 @@ module.exports = { date: ':attribute không phải là ngày hợp lệ', def: 'Thuộc tính :attribute có lỗi.', digits: ':attribute phải là số và có chiều dài bằng :digits.', + digits_between: 'Độ dài của trường :attribute phải nằm trong khoảng :min and :max chữ số.', different: 'Giá trị của hai trường :attribute và :different phải khác nhau.', 'in': 'Giá trị được chọn của :attribute không hợp lệ.', integer: ':attribute phải là số nguyên.', diff --git a/src/lang/zh.js b/src/lang/zh.js index 78c8fffa..cab0fc74 100755 --- a/src/lang/zh.js +++ b/src/lang/zh.js @@ -9,6 +9,7 @@ module.exports = { date: ':attribute日期格式错误.', def: ':attribute属性错误.', digits: ':attribute必须是:digits位小数.', + digits_between: ':attribute 必须是介于 :min 和 :max 位的数字。', different: ':attribute和:different必须不同.', 'in': '选择的:attribute无效', integer: ':attribute必须是一个整数.', diff --git a/src/lang/zh_TW.js b/src/lang/zh_TW.js index 556af4fe..6db9b7f0 100755 --- a/src/lang/zh_TW.js +++ b/src/lang/zh_TW.js @@ -9,6 +9,7 @@ module.exports = { date: ':attribute的日期格式錯誤。', def: ':attribute屬性錯誤。', digits: ':attribute必須是:digits位小數。', + digits_between: ':attribute 必須介於 :min 至 :max 位數字。', different: ':attribute和:different必須不同。', 'in': '選擇的:attribute無效', integer: ':attribute必須是一個整數。', diff --git a/src/rules.js b/src/rules.js index e8f0abae..a53f7a4b 100755 --- a/src/rules.js +++ b/src/rules.js @@ -307,6 +307,20 @@ var rules = { return false; }, + digits_between: function(val) { + var numericRule = this.validator.getRule('numeric'); + var req = this.getParameters(); + var valueDigitsCount = String(val).length; + var min = parseFloat(req[0], 10); + var max = parseFloat(req[1], 10); + + if (numericRule.validate(val) && valueDigitsCount >= min && valueDigitsCount <= max) { + return true; + } + + return false; + }, + regex: function(val, req) { var mod = /[g|i|m]{1,3}$/; var flag = req.match(mod);