Regex allows only 1 character

后端 未结 6 1434
长情又很酷
长情又很酷 2021-01-22 03:50
$rex = \'/^[^<,\"@?=>|;#]$/i\';

I\'m having trouble with this regular expression. The idea is that the input fields are checked for certain chara

6条回答
  •  礼貌的吻别
    2021-01-22 04:03

    You have the $ after your expression and the ^ in the beginning, which means you are accepting exactly one character.

    EDIT (based on the comments):

    You can try to see if your input fields only have valid characters, by matching it against this (if it matches, it means there are no invalid characters):

    $rex = '/^[^<,"@$?=>|;#]+$/i'
    

    You can also do the reverse, that is, test if your input fields have any invalid characters, using the regex provided by chaos:

    $rex = '/[<,"@$?=>|;#]/';
    

    This way, if the regex matches, then it means you have invalid characters.

提交回复
热议问题