JSFiddle - React, Tailwind, and code Playground

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/lib/cleave-phone.i18n.js"></script>
<div ng-app="app" ng-controller="AppController">
    <section>
        <input cleave options="options.creditCard" type="text" placeholder="Enter credit card number" ng-model="model.creditCard" />
        <p>Type: {{model.creditCardType}}</p>
    </section>

    <section>
        <input cleave options="options.phone" type="text" placeholder="Enter AU phone number" ng-model="model.phone" />
    </section>

    <section>
        <input cleave options="options.date" type="text" placeholder="Enter date: DD/MM/YYYY" ng-model="model.date" />
    </section>

    <section>
        <input cleave options="options.numeral" type="text" placeholder="Enter numeral" ng-model="model.numeral" class="input-numeral"/>
    </section>

    <section>
        <input cleave options="options.custom" type="text" ng-model="model.custom" />
    </section>
</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.onCreditCardTypeChanged = function(type) {
    $scope.model.creditCardType = type;
  };

  $scope.model = {
    creditCard: '',
    creditCardType: 'unknown',
    phone: '',
    date: '',
    numeral: '',
    custom: 'PREFIX-'
  };

  $scope.options = {
    creditCard: {
      creditCard: true,
      onCreditCardTypeChanged: $scope.onCreditCardTypeChanged
    },

    phone: {
      phone: true,
      phoneRegionCode: 'AU'
    },

    date: {
      date: true
    },

    numeral: {
      numeral: true
    },

    custom: {
      blocks: [6, 3, 3, 3],
      prefix: 'PREFIX',
      uppercase: true,
      delimiter: '-'
    }
  };

});