Archive for April 24, 2007

JavaScript Regular Expression OR

Posted in JavaScript, Software, Web, internet, programming on April 24, 2007 by Joey

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.