The backslash character in JavaScript strings is an escape character, so the backslashes that you have in your string elude the next character for the string, not the regular expression. So, right at the beginning, in your "^(\+? Backslash just escapes + for the line (which doesn't need it), and what the regular expression sees is just raw + where nothing happens again. From here error.
Fortunately, JavaScript has a literal syntax for regular expressions (with delimiters with / characters), which is likely to be the best starting point for you:
var re = /^(\+?|(\(\+?[0-9]{1,3}\))|)([ 0-9.\/-]|\([ 0-9.\/-]+\))+((x|X|((e|E)(x|X)(t|T)))([ 0-9.\/-]|\([ 0-9.\/-]+\)))?$/; alert(re.test("test input"));
Then at least backslashes are escaped in the regular expression, not in the string. (Note that since / is a delimiter for a regular expression literal, we need to avoid it (with a backslash).)
I have not exhaustively examined the actual regex, but this should get you started.
More on regex literals in the specification , of course, and here on the MDC .
source share