preg_match special characters

[\W]+ will match any non-word character.

but to match only the characters from the question, use this:

  $string="sadw$"
  if(preg_match("/[\[^\'£$%^&*()}{@:\'#~?><>,;@\|\\\-=\-_+\-¬\`\]]/", $string)){
   //this string contain atleast one of these [^'£$%^&*()}{@:'#~?><>,;@|\-=-_+-¬`] characters
  }

Leave a Comment