Nethra Nethra - 4 months ago 6x
Javascript Question

How to remove the hyphens from the phone number

I have the phone number stored in the database in the '234-565-1233' format. I want to remove the hypens from this Following is the code i tried but nothing worked.'OncallDDl' hold the phone number value with hyphens.I want the value to be returned as 2345651233. Can anyone hlpe me please

var str = OncallDDL.Text;
var newstr = str.Replace("/-/g",""); /error
var newStr = str.Replace(/-/g, ""); /error
var newStr = str.Replace("-", ""); /error
var newStr = str.Replace("\\D", ""); /error


You don't need regular expressions for this.

var str = OncallDDL.Text;
var newstr = str.Replace("-","");