search

Home  >  Q&A  >  body text

javascript - How to know if a string contains special characters?

For example: var regVal = '\w ';

How to know if it contains a backslash?

滿天的星座滿天的星座2753 days ago555

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-19 10:40:52

    /\/.test(regVal);

    In addition, your regVal assignment may not achieve the purpose. The backslashes in the string literal must be escaped:

    var regVal = "\w+";

    reply
    0
  • Cancelreply