tags:

views:

39

answers:

1

hi, how can i not allow these chars: \ / " ' [ ] { } | ~ ` ^ &

using javascript regular expression pattern thanks a lot

A: 

Check a string contains one of these characters:

if(str.match(/[\\\/"'\[\]{}|~`^&]/)){
  alert('not valid');
}

Validate a whole string, start to end:

if(str.match(/^[^\\\/"'\[\]{}|~`^&]*$/)){
  alert('it is ok.');
}
Kobi
Or to remove those characters: `str = str.replace(/[\\\/"'\[\]{}|~\`^`
Anonymous