开发者

How to detect ndash entity embedded in a textarea using Javascript?

I have a textarea within an HTML page into which my users paste content.

There is often an "–" (&ndash开发者_JAVA百科;)(\x2013) embedded in that content. I need to detect and replace it and store it in a database as –.

My code document.getElementById("input").value.replace("-", "–"); only detects the "-" (minus sign)(\x2D).

What would be the proper parameter to detect the ndash?


Use its Unicode code point in a pattern literal

document.getElementById("input").value.replace( /\u2013/g, "–");


Maybe:

document.getElementById("input").value.replace(String.fromCharCode(150), "–");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜