function test(text) { if (text.match(/[\!\@#\$\%\^\&\*\(\)\+\=\-\[\]\\\'\;\,\/\{\}\|\"\:\<\>\?]/)) { alert('非法字符'); } } test('&')