how to make date Auto Format in input textbox with javascript
when input yyyyMMdd
format in textbox, that will automatically change to yyyy/MM/dd
format
for example:
if your type 20120427
, that will change to 2012/04/27
how to make date Auto Format in input textbox with javascript
when input yyyyMMdd
format in textbox, that will automatically change to yyyy/MM/dd
format
for example:
if your type 20120427
, that will change to 2012/04/27
2 Answers
Reset to default 5you can try this javaScript Function and Call it from onChange
event of your textbox
function dateFormat(el){
value = el.value;
el.value = value.replace(/^([\d]{4})([\d]{2})([\d]{2})$/,"$1/$2/$3");
}
First, you need to write a function to do the convert,
function convert(original){};
then listen to onkeyup
evnets, and pass the value of the input to the convert function, set the input's value to its result