-3

I have here a javascript code that filters special characters. But what I really want is to filter all special characters except space. Hope you can help me with this. Thanks a lot in advance!

function valid(f) {
    !(/^[A-zÑñ0-9]*$/i).test(f.value)?f.value = f.value.replace(/[^A-zÑñ0-9]/ig,''):null;
} 
4

1 回答 1

0

在正则表达式中,\s 表示空格。所以请试试这个表达式:

/[^\s]*/gi 

此表达式匹配除 " " 之外的所有字符

于 2013-08-11T12:32:08.627 回答