How to slice the input text Field Value using Angular JS
HTML FORM
<form>
<input type="text" ng-model="cardExp">
</form>
JS
console.log($scope.cardExp) //output : 122016
I want to make text field value ("122016") into variables a and b and their vales are
a is first two digits
b is next 4 digits
Thanks,
You can use plain javascript.
var a = $scope.cardExp.substring(0, 2);
var b = $scope.cardExp.substring(2);
var app = angular.module('store', []);
app.controller('StoreController', function($scope) {
$scope.str = '122016';
$scope.splited = $scope.str.match(/.{1,4}/g);
$scope.a = $scope.splited[0];
$scope.b = $scope.splited[1];
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.