credit card form

HTML

<input type="text" id="test_form" />

JavaScript

$('#test_form').on('keyup', function(e){
		var val = $(this).val();
		if(e.which != 8)
		{
			if(val.replace(/\s/g, '').length % 4 == 0)
			{
				$(this).val(val + ' ');
			}
		}
		else
		{
			$(this).val(val);        
		}
	})