开发者

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

开发者 https://www.devze.com 2022-12-22 21:58 出处:网络
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 a

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

精彩评论

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

关注公众号