'C12345678'.match("^C\d{8}$")
and
'C12345678'.match("^C\[0-9]{8}$")
Why does this statement has different values?
'C12345678'.match("^C\d{8}$")
and
'C12345678'.match("^C\[0-9]{8}$")
Why does this statement has different values?
Because in the first case you need to escape the backslash:
console.log('C12345678'.match("^C\\d{8}$"));
As pointed out by Wiktor in the comment below, it's best to use the Regex literal syntax:
console.log('C12345678'.match(/^C\d{8}$/));