Your current code is testing to see if your string does NOT consist entirely of illegal characters. That isn't going to give you what you want. What you want to test for is if there are ANY illegal characters. To do that, you can do this:
if(/[#"\/:*?<>|;^]/.test("test word")){
alert('this includes illegal characters #"\/:*?<>|;^');
}
This removes the ^ and the $ so you can find any illegal characters and it changes the sense of the boolean test. This way, it hits the if statement if ANY illegal character is found anywhere in the string.
FYI, it is generally better to test to see if your string contains ONLY "legal" characters rather than the other way around because this way you might be letting control characters or other things like that through that you haven't thought of.
A test for all legal characters might look like this (you have to fill in the exact legal characters):
if (!/^[a-zA-Z. ]+$/.test("test word")){
alert('some illegal characters present');
}
/and the literal closing square bracket or the literal^(if it is at first position in the class).*- zero or more occurrences, remove it and flip your boolean totrue. also use===over==.^and$) and the quantifier*