Regex to check if whitespace present?

后端 未结 5 1113
误落风尘
误落风尘 2021-02-13 01:08

Seems pretty simple, but cannot figure out why this javascript code isn\'t working returning false, when expecting true) - I\'m guessing it has got to do something with the esca

5条回答
  •  终归单人心
    2021-02-13 01:45

    You don't need the brackets, you would need to escape the backslash (if using the string form) and the built-in regex syntax is easier because you don't have to escape backslashes when using the built-in regex syntax.

    var inValid = /\s/;
    var value = "test space";
    var k = inValid.test(value);
    alert(k);

提交回复
热议问题