2010-04-03 2 views
2

:자바 스크립트 정규 표현식 내가이 문자를 허용하지 수있는 방법을

\/" '[] {} | ~`^ 자바 스크립트 정규 표현식 패턴을 사용하여 &

+0

의 중복 가능성 http://stackoverflow.com/questions/705672/regular-expression-to-allow-a-set-of-characters-and-disallow-others – outis

+0

기타 : http://stackoverflow.com/questions/756567/regular-expression-for-excluding-special-characters, http://stackoverflow.com/questions/1152844/regex-for-alphanumeric-and-the-character , http://stackoverflow.com/questions/1763071/negate-characters-in-regular-expression, http://stackoverflow.com/questions/834002/regular-expression-that-includes-all-keyboard-characters-except - 그리고, ... – outis

+0

그리고 (PHP 태그에도 불구하고) : http://stackoverflow.com/questions/1778958/php-regular-expression-accept-selected-characters-only, http://stackoverflow.com/questions/ 878715/check-string-for-wrong-characters-using-reg 웅변 표현. – outis

답변

1

확인 문자열에는 다음 문자 중 하나가 포함됩니다.

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

Validat 개 전체 문자열은 종료 시작 :

if(str.match(/^[^\\\/"'\[\]{}|~`^&]*$/)){ 
    alert('it is ok.'); 
} 
+2

또는 그 문자를 지우려면 :'str = str.replace (/ [\\\/" '\ [\] {} | ~ \'^ &]/g," ");' – Anonymous