Skip to content

Commit

Permalink
validateBTCAddress directive
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmabc committed May 31, 2015
1 parent ae85850 commit 35c2642
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions html/directives/validateBitcoinAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
angular.module('app').directive("validateBitcoinAddress", function() {
return {
require: 'ngModel',
link: function(scope, ele, attrs, ctrl) {

ctrl.$parsers.unshift(function(value) {
if(value){
// test and set the validity after update.
var valid = window.bitcoinAddress.validate(value);
ctrl.$setValidity('validateBitcoinAddress', valid);
}

// if it's valid, return the value to the model,
// otherwise return undefined.
return valid ? value : undefined;
});

ctrl.$formatters.unshift(function(value) {
// validate.
ctrl.$setValidity('validateBitcoinAddress', window.bitcoinAddress.validate(value));

// return the value or nothing will be written to the DOM.
return value;
});


}
}

});

0 comments on commit 35c2642

Please sign in to comment.