cleave angular demo
cleave angular demo
by nosir
HTML
<script src="https://nosir.github.io/cleave.js/dist/cleave-angular.min.js"></script>
<script src="https://nosir.github.io/cleave.js/dist/cleave-phone.i18n.js"></script>
<div ng-app="app" ng-controller="AppController">
<section>
<input cleave="options.sortCode" on-value-change="onSortCodeValueChange" type="text" placeholder="Enter sortCode: xx-xx-xx" ng-model="model.sortCode" class="input-numeral" />
</section>
<pre ng-bind="model | json"></pre>
</div>
CSS
input {
width: 80%;
display: block;
outline: none;
-webkit-appearance: none;
border: 1px solid #e6e6e6;
border-radius: 5px;
background-color: #fff;
line-height: 30px;
vertical-align: middle;
height: 33px;
font-size: 14px;
padding: 0 8px;
}
.input-numeral {
text-align: right;
}
.right {
text-align: right;
}
body {
font-family: sans-serif;
}
p {
margin: 0;
padding: 5px 0 0 0;
font-size: 14px;
color: #666;
}
section {
margin-bottom: 15px;
width: 50%;
}
.input-numeral {
text-align: right;
}
JavaScript
angular.module('app', ['cleave.js'])
.controller('AppController', function($scope) {
$scope.onSortCodeValueChange = function(formattedValue) {
$scope.model.sortCodeFormatted = formattedValue;
};
$scope.model = {
sortCode: '',
sortCodeFormatted: ''
};
$scope.options = {
sortCode: {
numericOnly: true,
delimiter: '-',
blocks: [2, 2, 2]
}
};
});