Dodanie myślnika do kodu pocztowego

function autoCompletePostCode(inputId){
	$('body').on('keyup', inputId, function(event) {
		var liveInputValue = $(this).val();

		//if input lenght i equal 2 and keaborad key != backspace
		if (liveInputValue.length === 2  && event.keyCode !== 8) {
			$(inputId).val(liveInputValue+'-');
			return;
		}

		//if 4nth char in value is equal '-' delete it 
		if (liveInputValue.length === 4 && liveInputValue.charAt(3) === '-') {
			$(inputId).val(liveInputValue.slice(0,-1));
			return;
		}
		//limited lenght to five chars
		if (liveInputValue.length > 6){
			$(inputId).val(liveInputValue.slice(0,-1));
		}

	});
}
Komentarze wyłączone