Repository: baianat/vee-validate (js)

Issue:
Regex rule on array
Versions
 - vee-validate: 2.1.0-beta.8
  - vue: 2.5.16

I am trying to validate a field having multiple tags. Every tag should be validated as per a particular regex. If I use a single value then it works fine but fails for multiple values i.e. array field. 

I checked the code and found out that regex rule is not handling array field.  Is this by design? 

Pull request description:
feat: handle array for regex rule closes #1577
Added support to handle regex rule for array field.

Patch:
diff --git a/docs/guide/custom-rules.md b/docs/guide/custom-rules.md
index e16a82e3..8d19b6dd 100644
--- a/docs/guide/custom-rules.md
+++ b/docs/guide/custom-rules.md
@@ -75,39 +75,6 @@ Then you can use your rule like any other rule:
   When the field under validation is __not__ required, your rule may not be executed at all. This is because VeeValidate skips validation for empty fields if they are not required.
 :::
 
-## Args and Rule Configuration
-
-Your rule may provide different results/behavior depending on some configuration, as mentioned before they are passed as an array of values to the validator function, which may not always be optimal, for example a rule with 3 optional parameters would need to recieve all 3 parameters each time just to specify the third parameter.
-
-You can recieve an object instead of an array for your validation rule by providing a `paramNames` array in the extend options (third parameter). Which names the params in the array you would normally recieve.
-
-For an example take a look at a basic __value between__ rule implementation:
-
-```js
-const isBetween = (value, { min, max } = {}) => {
-  return Number(min) <= value && Number(max) >= value;
-};
-
-// The first param is called 'min', and the second is called 'max'.
-const paramNames = ['min', 'max'];
-
-Validator.extend('between', isBetween, {
-  paramNames //  pass it in the extend options.
-});
-```
-
-The paramNames isn't really required, but it allows your rule to work in both string/object formats. since there is no way in the string format to pass the named parameters:
-
-```
-between:10,20
-```
-
-The order is what controls the param names in that case. The validator will use the `paramNames` to convert the array of strings to an object containing the named parameters as keys with the correct param value. Make sure to order the `paramNames` in the same order that the params will be specified in the string format.
-
-::: danger
-Locale methods will still recieve the array of args, it will not convert it to an object at the time being due to the possible breaking changes in locale files.
-:::
-
 ## Target Dependant Rules
 
 Sometimes your rules may need to compare the field value against another field value, some built in rules like `confirmed`, `before` and `after` need a target field to compare against.
diff --git a/docs/guide/rules.md b/docs/guide/rules.md
index 39885ca1..6f5c754a 100644
--- a/docs/guide/rules.md
+++ b/docs/guide/rules.md
@@ -263,10 +263,6 @@ The file added to the field under validation must be an image (jpg,svg,jpeg,png,
 
 The field under validation must be a valid email.
 
-### email params
-
-Email rule can recieve any args from [validator.js isEmail](https://github.com/chriso/validator.js) validator. Note that to be able to configure it you need to use the object format.
-
 <input v-validate="'email'" data-vv-as="email" :class="{'input': true, 'is-danger': errors.has('email_field') }" name="email_field" type="text" placeholder="Your Email">
 <span v-show="errors.has('email_field')" class="help is-danger">{{ errors.first('email_field') }}</span>
 
@@ -559,7 +555,7 @@ The field under validation must be a valid url. Protocols are not required by de
 
 ### url params
 
-This rule can recieve any args from [validator.js isURL](https://github.com/chriso/validator.js) validator. Note that to be able to configure it you need to use the object format and pass the params as an object.
+- `require_protocol:` If the protocol should be required. It's set to false by default. Passing anything will require it.
 
 <input v-validate="'url:require_protocol'" data-vv-as="field" :class="{'input': true, 'is-danger': errors.has('url_field') }" name="url_field" type="text" placeholder="Enter a url">
 <span v-show="errors.has('url_field')" class="help is-danger">{{ errors.first('url_field') }}</span>
diff --git a/docs/guide/syntax.md b/docs/guide/syntax.md
index 3c9ecc81..454ea038 100644
--- a/docs/guide/syntax.md
+++ b/docs/guide/syntax.md
@@ -23,25 +23,12 @@ const multiple = {
 
 ## Rules Parameters
 
-Some rules can have parameters, which can be specified in multiple ways for convience:
-
-- As a comma seperated list which is suitable for the string format.
-- An array containing the params values (Suitable for the object format).
-- An object (Provides more complex configuration for the rules in object format), but with a [caveat](/guide/custom-rules.md#args-and-rule-configuration).
+Some rules can have parameters, which are passed in a comma separated list without spaces or an array for the object form:
 
 ```js
-// Params as a string
-const someRule = 'included:1,2,3,4';
-
-// Params as an array.
-const someRuleObj = { included: [1, 2, 3, 4] };
+const someRule = 'in:1,2,3,4';
 
-// Params as an object.
-const someCplxObj = {
-  email: {
-    allow_utf8_local_part: true
-  }
-};
+const someRuleObj = { in: [1, 2, 3, 4] };
 ```
 
 ::: tip
diff --git a/package.json b/package.json
index 85306cb5..b86baed2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "vee-validate",
-  "version": "2.1.0-beta.9",
+  "version": "2.1.0-beta.8",
   "description": "Simple Vue.js input validation plugin",
   "author": "Abdelrahman Awad <logaretm1@gmail.com>",
   "license": "MIT",
diff --git a/src/rules/regex.js b/src/rules/regex.js
index 2e157953..979370e0 100644
--- a/src/rules/regex.js
+++ b/src/rules/regex.js
@@ -3,6 +3,10 @@ const validate = (value, { expression }) => {
     expression = new RegExp(expression);
   }
 
+  if (Array.isArray(value)) {
+    return value.every(val => validate(val, { expression }));
+  }
+
   return expression.test(String(value));
 };
 


Test patch:
diff --git a/tests/unit/rules/regex.js b/tests/unit/rules/regex.js
index 92fdf622..68386451 100644
--- a/tests/unit/rules/regex.js
+++ b/tests/unit/rules/regex.js
@@ -7,6 +7,8 @@ test('validates regular expressions', () => {
   expect(validate('abc-123', { expression })).toBe(false);
   expect(validate('1234abc5', { expression })).toBe(false);
   expect(validate('', { expression })).toBe(false);
+  expect(validate(['1234567890', '321'], { expression })).toBe(true);
+  expect(validate(['1234567890', 'abc'], { expression })).toBe(false);
 });
 
 test('validates with strings as regular expressions', () => {
@@ -16,4 +18,6 @@ test('validates with strings as regular expressions', () => {
   expect(validate('abc-123', { expression })).toBe(false);
   expect(validate('1234abc5', { expression })).toBe(false);
   expect(validate('', { expression })).toBe(false);
+  expect(validate(['1234567890', '321'], { expression })).toBe(true);
+  expect(validate(['1234567890', 'abc'], { expression })).toBe(false);
 });