JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input name="reg" id="reg" type="text">
</form>
JavaScript
$reg = $( '#reg' );
$reg.blur( function() {
while( this.value.length < 4 )
{
this.value = '0' + this.value;
}
} );