JSFiddle - React, Tailwind, and code Playground

by Ahmad Asjad

HTML

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<input type="text" class="us_zip" />

JavaScript

$(document).ready(function(){
	$('body').on('blur','.us_zip',function(){
		$(this).val(IsValidZipCode($(this).val()));
	});
	$('body').on('keyup','.us_zip',function(event){
		event = event || window.event;
		if((event.which>95 && event.which<106) || (event.which>47 && event.which<58)){
			$(this).val(IsValidZipCode($(this).val()));
		}
	});
});

function IsValidZipCode(zip) {
	var numbers = zip.replace(/\D/g, '');
	//var numbers = zip;
	var new_value = '';
	new_value = numbers.substr(0, 5);
	return new_value;
}