Jquery ile anlık olarak yapabilirsin.
$('.kartnumarasi').keyup(function() {
var foo = $(this).val().split("-").join(""); // remove hyphens
if (foo.length > 0) {
foo = foo.match(new RegExp('.{1,4}', 'g')).join("-");
}
$(this).val(foo);
});Çalıştırmak içinde
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="kartnumarasi" value="1234-1234-1234-1234" />