Jun 2, 2009 #1 apex82 Programmer Joined Mar 2, 2009 Messages 127 Location GB Hi, I would like to format a date in a form field so when a user adds 01012001 This would be returned as 01/01/2001 I’ve searched Google for an example but can’t find anything. Can anyone help? Thanks.
Hi, I would like to format a date in a form field so when a user adds 01012001 This would be returned as 01/01/2001 I’ve searched Google for an example but can’t find anything. Can anyone help? Thanks.
Jun 2, 2009 #2 BillyRayPreachersSon Programmer Joined Dec 8, 2003 Messages 17,047 Location GB Assuming the date entered will ALWAYS be 8 digits, you can use: Code: var dateStr = '01042009'; var dd = dateStr.substr(0, 2); // 01 var mm = dateStr.substr(2, 2); // 04 var yyyy = dateStr.substr(4); // 2009 I'd recommend using 'onblur' on the input to run its value through that code. Hope this helps, Dan Coedit Limited - Delivering standards compliant, accessible web solutions Dan's Page [blue]@[/blue] Code Couch: http://www.codecouch.com/dan/ Code Couch Tech Snippets & Info: http://www.codecouch.com/ Upvote 0 Downvote
Assuming the date entered will ALWAYS be 8 digits, you can use: Code: var dateStr = '01042009'; var dd = dateStr.substr(0, 2); // 01 var mm = dateStr.substr(2, 2); // 04 var yyyy = dateStr.substr(4); // 2009 I'd recommend using 'onblur' on the input to run its value through that code. Hope this helps, Dan Coedit Limited - Delivering standards compliant, accessible web solutions Dan's Page [blue]@[/blue] Code Couch: http://www.codecouch.com/dan/ Code Couch Tech Snippets & Info: http://www.codecouch.com/
Jun 3, 2009 #3 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi Code: slashed=slashless.replace(/(..)(..)/,'$1/$2/') Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote