1

I need a regular expression for the following data:

All digits, all letters, or combination of digits and letters including special characters allowed:

@ . – ‘ ? , ( ) : ; ! * $  _  =  + ^  &  #

and French Unicode Accent Characters.

Please help. I am using the following regular expression, which works fine for other characters but it somehow allows forward slash(/).

VALIDATOR_STRING = "^[A-Za-z0-9éÉèÈçÇâÂêÊôÔ@.'#,-?:;!*$_=+^&()]+$";
4

1 に答える 1

7

-文字クラス ( のように) でダッシュを使用する場合、範囲を示します (この例では、とA-Zの間のすべての大文字)。AZ

,-?したがって、スラッシュを含む範囲を許可します。http://www.asciitable.comを見ると、この範囲に次の文字がすべて含まれていることがわかります。, . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

この動作を回避するには、ダッシュを文字クラスの最初または最後の文字として配置します。

VALIDATOR_STRING = "^[-A-Za-z0-9éÉèÈçÇâÂêÊôÔ@.'#,?:;!*$_=+^&()]+$";
于 2013-09-19T12:26:28.830 に答える