-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;
} 
Kaye
  • 21
  • 2
  • 8
  • 2
    So what does PHP have to do with it? Have you tried, you know, adding a space character to the list of allowed characters in the regex? – JJJ Aug 11 '13 at 12:10

1 Answers1

0

In regular expression \s means space. So please try this expression:

/[^\s]*/gi 

this expression match all characters except " "

  • hi jason! i tried you code and it does filter all characters except "space". but what i want is for it to allow Alphanumeric characters AND "SPACE" to be inputted in a textbox.and filter other special characters. hope you can give me some more ideas.thanks! – Kaye Aug 11 '13 at 12:40
  • Got it! Thank you guys for your help :) Thanks Jason Chelsea for the idea :) here's my code: – Kaye Aug 11 '13 at 12:46
  • function valid(f) { !(/^\s[A-zÑñ0-9 ]*$/i).test(f.value)?f.value = f.value.replace(/[^\s;A-zÑñ0-9]/ig,''):null; } – Kaye Aug 11 '13 at 12:46