I have a new query on datepicker. I want to replace forward slash with comma (or dot) from date which is pick from datepicker. I tried some code below but it's 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('/', '.'));
});
As the forward slash (/) is special character in regular expressions, it has to be escaped with a backward slash (\). Also, to replace all the forward slashes on the string, the global modifier (g) is used. It will replace all the forward slashes in the given string.
To replace all forward slashes in a string:Call the replace() method, passing it a regular expression that matches all forward slashes as the first parameter and the replacement string as the second. The replace method will return a new string with all forward slashes replaced.
Use Find & Replace to Evaluate Cells (The keyboard shortcut to bring up this window is Ctrl + H .) If your dates are formatted with forward slashes (/), you are going to enter a forward slash into BOTH the Find what and Replace with fields. If your dates are formatted with dashes (-), then use dashes.
replace('\','\\') which converts first string to second one.
Here
use regular expression. THis will work for you
$("#txtDate").datepicker({
changeMonth: true
});
$("#btnConvert").click(function(){
$("#spnCurrentDate").html($('#txtDate').val().replace(/\//g, ""));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With