Page 1 of 1

preg_match_all help

Posted: Sun Jan 03, 2010 12:18 am
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.

Re: preg_match_all help

Posted: Sun Jan 03, 2010 2:02 am
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]));
  }
?>

Re: preg_match_all help

Posted: Sun Jan 03, 2010 2:03 am
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))