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

Commit

Permalink
Fixed issue #99 to support backslash inside alt
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ghiscoding committed Jan 5, 2016
1 parent 450d4fb commit 5b460b9
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.4.18",
"version": "1.4.19",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": [
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Angular-Validation change logs

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
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)
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.
1.4.16 (2015-12-11) Fixed issue #90 blinking error messages.
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-validation.min.js

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions more-examples/customValidation/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

vmd.myIbanCheck1 = function(inputModel) {
return { isValid: IBAN.isValid(inputModel), message: 'Invalid IBAN.' };
}

vmd.submitForm = function() {
if(vs.checkFormValidity(vmd.form1)) {
alert('All good, proceed with submit...');
Expand All @@ -55,7 +59,8 @@ myApp.controller('CtrlService', ['$scope', 'validationService', function ($scope

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

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

vms.myIbanCheck2 = function(inputModel) {
return { isValid: IBAN.isValid(inputModel), message: 'Invalid IBAN.' };
}

vms.submitForm = function() {
if(new validationService().checkFormValidity(vms.form2)) {
alert('All good, proceed with submit...');
Expand Down
21 changes: 18 additions & 3 deletions more-examples/customValidation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ <h4><strong>ERRORS!</strong></h4>
placeholder="alpha|min_len:2|custom:vmd.myCustomValidation2|required"
validation="alpha|min_len:2|custom:vmd.myCustomValidation2|required" />
</div>
<div class="form-group">
<label for="iban1">Valid IBAN</label>
<input type="text" class="form-control"
name="iban1"
ng-model="vmd.model.iban1"
placeholder="custom:vmd.myIbanCheck1(vmd.model.iban1)|required"
validation="custom:vmd.myIbanCheck1(vmd.model.iban1)|required" />
</div>
<div class="form-actions">
<button type="submit" name="btn_ngDisabled1" class="btn btn-primary" ng-disabled="vmd.form1.$invalid" >{{ 'SAVE' | translate }} (ngDisabled)</button>
<button type="submit" name="btn_ngSubmit1" class="btn btn-primary" ng-click="vmd.submitForm()">{{ 'SAVE' | translate }} (ngSubmit)</button>
</div>
</form>
</div>
</div>

<hr/>

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

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

<!-- Angular-Validation -->
<script type="text/javascript" src="../../dist/angular-validation.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-validation-ghiscoding",
"version": "1.4.18",
"version": "1.4.19",
"author": "Ghislain B.",
"description": "Angular-Validation Directive and Service (ghiscoding)",
"main": "app.js",
Expand Down
29 changes: 19 additions & 10 deletions protractor/custom_spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
describe('Angular-Validation Custom Javascript Validation Tests:', function () {
// global variables
var formElementNames = ['input1', 'input2', 'input3', 'input4'];
var defaultErrorMessage = 'May only contain letters. Must be at least 2 characters. Field is required.';
var errorTooShort = [
var formElementNames = ['input1', 'input2', 'iban1', 'input3', 'input4', 'iban2'];
var errorMessages = [
'May only contain letters. Must be at least 2 characters. Field is required.',
'May only contain letters. Must be at least 2 characters. Field is required.',
'Field is required.',
'May only contain letters. Must be at least 2 characters. Field is required.',
'May only contain letters. Must be at least 2 characters. Field is required.',
'Field is required.'
];
var errorTooShortOrInvalid = [
'Must be at least 2 characters. Alternate error message.',
'Must be at least 2 characters. Returned error from custom function.',
'Invalid IBAN.',
'Must be at least 2 characters. Alternate error message.',
'Must be at least 2 characters. Returned error from custom function.'
'Must be at least 2 characters. Returned error from custom function.',
'Invalid IBAN.',
];
var oneChar = ['a', 'd', 'a', 'd'];
var validInputTexts = ['abc', 'def', 'abc', 'def'];
var oneChar = ['a', 'd', 'iban', 'a', 'd', 'iban'];
var validInputTexts = ['abc', 'def', 'BE68539007547034', 'abc', 'def', 'BE68539007547034'];

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

for (var i = 0, j = 0, ln = itemRows.length; i < ln; i++) {
expect(itemRows.get(i).getText()).toEqual(defaultErrorMessage);
expect(itemRows.get(i).getText()).toEqual(errorMessages[i]);
}
});

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

var elmError = $('.validation-' + formElementNames[i]);
expect(elmError.getText()).toEqual(defaultErrorMessage);
expect(elmError.getText()).toEqual(errorMessages[i]);
}
});

Expand All @@ -55,7 +64,7 @@
elmInput.sendKeys('a');

var elmError = $('.validation-' + formElementNames[i]);
expect(elmError.getText()).toEqual(errorTooShort[i]);
expect(elmError.getText()).toEqual(errorTooShortOrInvalid[i]);
}
});

Expand Down Expand Up @@ -108,7 +117,7 @@
elmInput.sendKeys(protractor.Key.TAB);

var elmError = $('.validation-' + formElementNames[i]);
expect(elmError.getText()).toEqual(defaultErrorMessage);
expect(elmError.getText()).toEqual(errorMessages[i]);
}
});

Expand Down
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Angular Validation (Directive / Service)
`Version: 1.4.18`
`Version: 1.4.19`
### Form validation after user stop typing (default 1sec).

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!
Expand Down Expand Up @@ -179,7 +179,8 @@ All validators are written as `snake_case` but it's up to the user's taste and c
* `exact_len:n` Ensures that field length precisely matches the specified length (n).
* `float` as to be floating value (excluding integer)
* `float_signed` Has to be floating value (excluding int), could be signed (-/+) positive/negative.
* `iban` Check for a valid IBAN.
* ~~`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)

* `in` alias of `in_list`
* `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".
* `int` Only positive integer (alias to `integer`).
Expand Down
2 changes: 1 addition & 1 deletion src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ angular
// We first need to see if the validation holds a custom user regex, if it does then deal with it first
// 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
if(rules.indexOf("pattern=/") >= 0) {
var matches = rules.match(/pattern=(\/.*\/[igm]*)(:alt=(.*))?/);
var matches = rules.match(/pattern=(\/(?:(?!:alt).)*\/[igm]*)(:alt=(.*))?/);
if (!matches || matches.length < 3) {
throw 'Regex validator within the validation needs to be define with an opening "/" and a closing "/", please review your validator.';
}
Expand Down
Loading

0 comments on commit 5b460b9

Please sign in to comment.