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), "–");
精彩评论