Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace forward slash with comma from date [duplicate]

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('/', '.'));
});
like image 944
S. S. Rawat Avatar asked Jun 25 '14 12:06

S. S. Rawat


People also ask

How do I get rid of forward slash?

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.

How do you change a forward slash?

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.

What functions could you use to replace slashes for dashes in a list of dates?

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.

How do you replace single forward slash with double forward slash in java?

replace('\','\\') which converts first string to second one.


1 Answers

Here

use regular expression. THis will work for you

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

$("#btnConvert").click(function(){
$("#spnCurrentDate").html($('#txtDate').val().replace(/\//g, ""));
});
like image 152
Deep Sharma Avatar answered Oct 01 '22 06:10

Deep Sharma