Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 5b460b9

Browse files
committed
Fixed issue #99 to support backslash inside alt
- Inserting a backslash "\" inside an `alt:` (alternate message) was causing the validation to not work properly. - Also removed IBAN support as default validator, this should instead be validated through the help of custom validation and an external library like arhs/iban.js
1 parent 450d4fb commit 5b460b9

File tree

10 files changed

+473
-23
lines changed

10 files changed

+473
-23
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.4.18",
3+
"version": "1.4.19",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": [

changelog.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Angular-Validation change logs
22

3+
1.4.19 (2016-01-04) Fixed issue #99 support backslash inside `alt` (alternate message). IBAN should now be validated through custom validation (Wiki updated) with help of external library like arhs/iban.js
34
1.4.18 (2015-12-20) Fixed issue #91 interpolation problem with remove validation doesn't work twice. Enhancement #98 possibility to use one validation or another (tell how many Validators are required for field to become valid). Enhancement #97 possibility to validate even on empty text field (useful on `custom` and `remote` validation). Refined some Validators (IPV6 now include compressed/uncompressed addresses, added more Polish characters to other Validators)
45
1.4.17 (2015-12-15) Fixed issue #92 input name with '.', enhancement #94 Polish characters, issue #96 in_list wasn't accepting special characters.
56
1.4.16 (2015-12-11) Fixed issue #90 blinking error messages.

dist/angular-validation.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

more-examples/customValidation/app.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var myApp = angular.module('myApp', ['ghiscoding.validation', 'pascalprecht.translate', 'ui.bootstrap']);
3+
var myApp = angular.module('myApp', ['ghiscoding.validation', 'pascalprecht.translate']);
44
// --
55
// configuration
66
myApp.config(['$compileProvider', function ($compileProvider) {
@@ -37,6 +37,10 @@ myApp.controller('CtrlDirective', ['validationService', function (validationServ
3737
return { isValid: isValid, message: 'Returned error from custom function.'};
3838
}
3939

40+
vmd.myIbanCheck1 = function(inputModel) {
41+
return { isValid: IBAN.isValid(inputModel), message: 'Invalid IBAN.' };
42+
}
43+
4044
vmd.submitForm = function() {
4145
if(vs.checkFormValidity(vmd.form1)) {
4246
alert('All good, proceed with submit...');
@@ -55,7 +59,8 @@ myApp.controller('CtrlService', ['$scope', 'validationService', function ($scope
5559

5660
vs.setGlobalOptions({ scope: $scope })
5761
.addValidator('input3', 'alpha|min_len:2|custom:vms.myCustomValidation3:alt=Alternate error message.|required')
58-
.addValidator('input4', 'alpha|min_len:2|custom:vms.myCustomValidation4|required');
62+
.addValidator('input4', 'alpha|min_len:2|custom:vms.myCustomValidation4|required')
63+
.addValidator('iban2', 'custom:vms.myIbanCheck2(vms.model.iban2)|required');
5964

6065
vms.myCustomValidation3 = function() {
6166
// you can return a boolean for isValid or an objec (see the next function)
@@ -70,6 +75,10 @@ myApp.controller('CtrlService', ['$scope', 'validationService', function ($scope
7075
return { isValid: isValid, message: 'Returned error from custom function.'};
7176
}
7277

78+
vms.myIbanCheck2 = function(inputModel) {
79+
return { isValid: IBAN.isValid(inputModel), message: 'Invalid IBAN.' };
80+
}
81+
7382
vms.submitForm = function() {
7483
if(new validationService().checkFormValidity(vms.form2)) {
7584
alert('All good, proceed with submit...');

more-examples/customValidation/index.html

+18-3
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ <h4><strong>ERRORS!</strong></h4>
4343
placeholder="alpha|min_len:2|custom:vmd.myCustomValidation2|required"
4444
validation="alpha|min_len:2|custom:vmd.myCustomValidation2|required" />
4545
</div>
46+
<div class="form-group">
47+
<label for="iban1">Valid IBAN</label>
48+
<input type="text" class="form-control"
49+
name="iban1"
50+
ng-model="vmd.model.iban1"
51+
placeholder="custom:vmd.myIbanCheck1(vmd.model.iban1)|required"
52+
validation="custom:vmd.myIbanCheck1(vmd.model.iban1)|required" />
53+
</div>
4654
<div class="form-actions">
4755
<button type="submit" name="btn_ngDisabled1" class="btn btn-primary" ng-disabled="vmd.form1.$invalid" >{{ 'SAVE' | translate }} (ngDisabled)</button>
4856
<button type="submit" name="btn_ngSubmit1" class="btn btn-primary" ng-click="vmd.submitForm()">{{ 'SAVE' | translate }} (ngSubmit)</button>
4957
</div>
5058
</form>
51-
</div>
59+
</div>
5260

5361
<hr/>
5462

@@ -82,6 +90,13 @@ <h4><strong>ERRORS!</strong></h4>
8290
ng-model="vms.model.input4"
8391
placeholder="alpha|min_len:2|custom:vms.myCustomValidation4|required" />
8492
</div>
93+
<div class="form-group">
94+
<label for="iban2">Valid IBAN</label>
95+
<input type="text" class="form-control"
96+
name="iban2"
97+
ng-model="vms.model.iban2"
98+
placeholder="custom:vms.myIbanCheck2(vms.model.iban2)|required" />
99+
</div>
85100
<div class="form-actions">
86101
<button type="submit" name="btn_ngDisabled2" class="btn btn-primary" ng-disabled="vms.form2.$invalid" >{{ 'SAVE' | translate }} (ngDisabled)</button>
87102
<button type="submit" name="btn_ngSubmit2" class="btn btn-primary" ng-click="vms.submitForm()">{{ 'SAVE' | translate }} (ngSubmit)</button>
@@ -99,8 +114,8 @@ <h4><strong>ERRORS!</strong></h4>
99114
<script src="../../vendors/angular-translate/angular-translate.min.js"></script>
100115
<script src="../../vendors/angular-translate/angular-translate-loader-static-files.min.js"></script>
101116

102-
<!-- Angular-UI -->
103-
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.2.js"></script>
117+
<!-- IBAN external library -->
118+
<script src="../../vendors/iban/iban.js"></script>
104119

105120
<!-- Angular-Validation -->
106121
<script type="text/javascript" src="../../dist/angular-validation.min.js"></script>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-validation-ghiscoding",
3-
"version": "1.4.18",
3+
"version": "1.4.19",
44
"author": "Ghislain B.",
55
"description": "Angular-Validation Directive and Service (ghiscoding)",
66
"main": "app.js",

protractor/custom_spec.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
describe('Angular-Validation Custom Javascript Validation Tests:', function () {
22
// global variables
3-
var formElementNames = ['input1', 'input2', 'input3', 'input4'];
4-
var defaultErrorMessage = 'May only contain letters. Must be at least 2 characters. Field is required.';
5-
var errorTooShort = [
3+
var formElementNames = ['input1', 'input2', 'iban1', 'input3', 'input4', 'iban2'];
4+
var errorMessages = [
5+
'May only contain letters. Must be at least 2 characters. Field is required.',
6+
'May only contain letters. Must be at least 2 characters. Field is required.',
7+
'Field is required.',
8+
'May only contain letters. Must be at least 2 characters. Field is required.',
9+
'May only contain letters. Must be at least 2 characters. Field is required.',
10+
'Field is required.'
11+
];
12+
var errorTooShortOrInvalid = [
613
'Must be at least 2 characters. Alternate error message.',
714
'Must be at least 2 characters. Returned error from custom function.',
15+
'Invalid IBAN.',
816
'Must be at least 2 characters. Alternate error message.',
9-
'Must be at least 2 characters. Returned error from custom function.'
17+
'Must be at least 2 characters. Returned error from custom function.',
18+
'Invalid IBAN.',
1019
];
11-
var oneChar = ['a', 'd', 'a', 'd'];
12-
var validInputTexts = ['abc', 'def', 'abc', 'def'];
20+
var oneChar = ['a', 'd', 'iban', 'a', 'd', 'iban'];
21+
var validInputTexts = ['abc', 'def', 'BE68539007547034', 'abc', 'def', 'BE68539007547034'];
1322

1423
describe('When choosing `more-examples` custom javascript', function () {
1524
it('Should navigate to home page', function () {
@@ -25,7 +34,7 @@
2534
var inputName;
2635

2736
for (var i = 0, j = 0, ln = itemRows.length; i < ln; i++) {
28-
expect(itemRows.get(i).getText()).toEqual(defaultErrorMessage);
37+
expect(itemRows.get(i).getText()).toEqual(errorMessages[i]);
2938
}
3039
});
3140

@@ -44,7 +53,7 @@
4453
elmInput.sendKeys(protractor.Key.TAB);
4554

4655
var elmError = $('.validation-' + formElementNames[i]);
47-
expect(elmError.getText()).toEqual(defaultErrorMessage);
56+
expect(elmError.getText()).toEqual(errorMessages[i]);
4857
}
4958
});
5059

@@ -55,7 +64,7 @@
5564
elmInput.sendKeys('a');
5665

5766
var elmError = $('.validation-' + formElementNames[i]);
58-
expect(elmError.getText()).toEqual(errorTooShort[i]);
67+
expect(elmError.getText()).toEqual(errorTooShortOrInvalid[i]);
5968
}
6069
});
6170

@@ -108,7 +117,7 @@
108117
elmInput.sendKeys(protractor.Key.TAB);
109118

110119
var elmError = $('.validation-' + formElementNames[i]);
111-
expect(elmError.getText()).toEqual(defaultErrorMessage);
120+
expect(elmError.getText()).toEqual(errorMessages[i]);
112121
}
113122
});
114123

readme.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Angular Validation (Directive / Service)
2-
`Version: 1.4.18`
2+
`Version: 1.4.19`
33
### Form validation after user stop typing (default 1sec).
44

55
Forms Validation with Angular made easy! Angular-Validation is an angular directive/service with locales (languages) with a very simple approach of defining your `validation=""` directly within your element to validate (input, textarea, etc) and...that's it!!! The directive/service will take care of the rest!
@@ -179,7 +179,8 @@ All validators are written as `snake_case` but it's up to the user's taste and c
179179
* `exact_len:n` Ensures that field length precisely matches the specified length (n).
180180
* `float` as to be floating value (excluding integer)
181181
* `float_signed` Has to be floating value (excluding int), could be signed (-/+) positive/negative.
182-
* `iban` Check for a valid IBAN.
182+
* ~~`iban`~~ To properly validate an IBAN please use [Wiki - Custom Validation](https://github.com/ghiscoding/angular-validation/wiki/Custom-Validation-functions) with an external library like [Github arhs/iban.js](https://github.com/arhs/iban.js)
183+
183184
* `in` alias of `in_list`
184185
* `in_list:foo,bar,..` Ensures the value is included inside the given list of values. The list must be separated by ',' and also accept words with spaces for example "ice cream".
185186
* `int` Only positive integer (alias to `integer`).

src/validation-common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ angular
185185
// We first need to see if the validation holds a custom user regex, if it does then deal with it first
186186
// So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe
187187
if(rules.indexOf("pattern=/") >= 0) {
188-
var matches = rules.match(/pattern=(\/.*\/[igm]*)(:alt=(.*))?/);
188+
var matches = rules.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);
189189
if (!matches || matches.length < 3) {
190190
throw 'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';
191191
}

0 commit comments

Comments
 (0)