JSFiddle - React, Tailwind, and code Playground

by justinwyllie

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<input type="text" id="cc">

JavaScript

$(function() {

//https://developer.mozilla.org/en-US/docs/Web/Events/input for IE limitations
$('#cc').on('input', function() {
	  var v = $(this).val();
    if (v.length == 2) {
    	$(this).val(v + '-');	
    }
    
   if (v.length == 3) {
    	$(this).val(v.substring(0,2));	
    }
    

})



})