I see that it already answered correctly, but here is my occupation.
Adding the timeout function to the formatting function will allow the user to enter 4 characters before formatting and potentially confuse the user:
function sample(x) { setTimeout(function() { if (x.value.length > 2 && x.value.length < 5) { var first = x.value.substring(0, 2) + "'"; var second = x.value.substring(2, x.value.length) + "\""; x.value = first + second; } }, 1500);
Please see this CodePen for a working example: http://codepen.io/Tiketti/pen/YyVRwb?editors=101
source share