Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-4
rated 0 times [  1] [ 5]  / answers: 1 / hits: 76940  / 11 Years ago, tue, april 16, 2013, 12:00:00

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 escape characters? Could someone please help me write a JS block that will return true if whitespace present?



var inValid = new RegExp([s]);
var value = test space;
var k = inValid.test(value);
alert(k);

More From » regex

 Answers
0

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);




[#78858] Monday, April 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gabriellagiselc

Total Points: 654
Total Questions: 99
Total Answers: 106

Location: Burkina Faso
Member since Thu, Dec 23, 2021
3 Years ago
;