javascript - Auto-formatting input fields as user types -


i have short piece of jquery automatically insert '/' character after 2nd number entered date field. works expected, cannot figure out how allow user edit incorrect entry hitting backspace because code wants keep entering '/' after second character has been entered, keeps them being able start over. i've tried solve on own, skills aren't par yet. below code; appreciated. thank you.

$(document).ready(function () {     $("#cc-exp").keyup(function () {         if ($(this).val().length == 2) {             $(this).val($(this).val() + "/");         }     }); }); 

after continued research , experimentation, solution ended being use .keypress instead of .keyup. below final code.

$(document).ready(function () {     $("#cc-exp").keypress(function () {         if ($(this).val().length == 2) {             $(this).val($(this).val() + "/");         }     }); }); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -