2010-04-03 8 views
2

comment puis-je pas laisser ces caractères:javascript expressions régulières

\/"[] {} | ~`^&

utilisant javascript modèle d'expression régulière

+0

double possible de http://stackoverflow.com/questions/705672/regular-expression-to-allow-a-set-of-characters-and-disallow-others – outis

+0

Aussi: http://stackoverflow.com/questions/756567/expression-expressive-pour-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 -et, ... – outis

+0

Et (malgré les balises PHP): http://stackoverflow.com/questions/1778958/php-regular-expression-accept-selected-characters-only, http://stackoverflow.com/questions/ 878715/check-string-for-illegal-characters-using-reg ular-expression. – outis

Répondre

1

Vérifier une chaîne contient l'un de ces caractères:

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

Validat chaîne entière ea, début à la fin:

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

Ou pour supprimer ces caractères: 'str = str.replace (/ [\\\ /" '\ [\] {} | ~ \ '^ &]/g," ");' – Anonymous