preg_match_all help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingdm
Forum Commoner
Posts: 27
Joined: Thu Dec 03, 2009 9:32 am

preg_match_all help

Post by kingdm »

Can anyone help me regarding this preg_match_all I did.

Code: Select all

if(preg_match_all('/[^a-z0-9\.,$ñ\s-_]/i', $vesselname, $invalid)) 
                { 
                   $errors[] = "Vessel name contains invalid character: " . join('',array_unique($invalid[0]));
                }
 
This works fine however it won't allow the characters / () slash and open&close parentheses. I need those characters to be valid.

Thank you.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: preg_match_all help

Post by flying_circus »

I'm new at regular expressions, but here is my attempt at it

Code: Select all

<?php
  if(preg_match_all('/[^a-z0-9\.,$ñ\s-_/()\\{}]/i', $vesselname, $invalid)) {
    $errors[] = "Vessel name contains invalid character: " . join('',array_unique($invalid[0]));
  }
?>
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: preg_match_all help

Post by manohoo »

You are missing those characters in your regular expression. Try this:

Code: Select all

if(preg_match_all('/[^a-z0-9\.,$ñ\s-_\(\)\/]/i', $vesselname, $invalid))
Post Reply