You need to double-up on the backslashes in the pattern.
var pattern = "^[\\s\\da-zA-ZåäöÅÄÖ_]+$"
The problem is that when you build regular expression objects that way, there are two passes made over the string: one to interpret it as a string, and then a second to interpret it as a regular expression. Both of those micro-syntaxes use \
to mean something, so by doubling them you get a single backslash out of the string constant parse.
If your pattern is really a constant, and not something that you construct dynamically from separate parts, then you can just use the native syntax for regular expressions:
var pattern = /^[\s\da-zA-ZåäöÅÄÖ_]+$/;
Only one backslash is necessary because the pattern is only parsed once, as a regular expression.