emerald
emerald

Reputation: 329

Date Auto format with javaScript

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

Upvotes: 3

Views: 10899

Answers (2)

AKZap
AKZap

Reputation: 1211

you 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");        
}

Upvotes: 5

wong2
wong2

Reputation: 35750

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

Upvotes: -2

Related Questions