To specify an “OR” condition in JavaScript regular expressions, use the pipe character – |.
var StringToTest = “abc”;
var IsFound = /a|b/.test(StringToTest);
alert(IsFound);
The above statement returns true if ‘a’ or ‘b’ is in the test string.
Filed under: Internet, JavaScript, Programming, Software, Web | 1 Comment »