Remove a long dash from a string in JavaScript?

后端 未结 4 672
梦如初夏
梦如初夏 2021-02-05 11:05

I\'ve come across an error in my web app that I\'m not sure how to fix.

Text boxes are sending me the long dash as part of their content (you know, the special long dash

4条回答
  •  逝去的感伤
    2021-02-05 11:30

    There are three unicode long-ish dashes you need to worry about: http://en.wikipedia.org/wiki/Dash

    You can replace unicode characters directly by using the unicode escape:

    '—my string'.replace( /[\u2012\u2013\u2014\u2015]/g, '' )
    

提交回复
热议问题