How to replace a slash with a comma from a date

I have a new datepicker request. I want to replace the slash with a comma (or period) from a date selected from a datepicker. I tried the code below, but it does not work fine.

Fiddle Here

HTML

<input type='text' id='txtDate' readonly='true' />
<input type='button' id='btnConvert' value='Change' /><br/>
Current Date : <span id='spnCurrentDate'></span>

Js

$("#txtDate").datepicker({
    changeMonth: true
});

$("#btnConvert").click(function(){
$("#spnCurrentDate").html($('#txtDate').val().replace('/', '.'));
});
+4
source share
2 answers

Here

use regex. This will work for you.

$("#txtDate").datepicker({
    changeMonth: true
});

$("#btnConvert").click(function(){
$("#spnCurrentDate").html($('#txtDate').val().replace(/\//g, ""));
});
+2
source

You need to avoid the slash. Try the following:

$("#spnCurrentDate").html($('#txtDate').val().replace(/\//g, "."));

Working demo

+2
source

Source: https://habr.com/ru/post/1545993/


All Articles