Can you explain me why this regex is invalid ?
new RegExp("^(0|\+33)+[0-9]{9}$");
Validate by regex online
You need a double backslash before the first +, like this:
new RegExp("^(0|\\+33)+[0-9]{9}$");
When JavaScript evaluates the string, it reads \+ as simply +. Then the RegExp sees |+, which is two Regex operators back to back (or and repeat 1 to infinite times)...which is invalid.
Invalid regular expression: /^(0|+33)+[0-9]{9}$/: Nothing to repeatChrome/75.0.3770.90 console, and it worked perfectly. Returned this: /^(0|\+33)+[0-9]{9}$/Chrome 75.0.3770.100Your regex work as expected with regex literals. With the string literals you need to double escape the special chars.
const r = /^(0|\+33)+[0-9]{9}$/;
console.log(r.test('0782896736'));
console.log(r.test('+33782896736'));
console.log(r.test('blabla'));
const regexp = new RegExp('^(0|\\+33)+[0-9]{9}$');
console.log(regexp.test('0782896736'));
console.log(regexp.test('+33782896736'));
console.log(regexp.test('blabla'));
+character