View Single Post
  #2 (permalink)  
Old 04-13-2008, 02:51 AM
David Powers
 
Posts: n/a
Diggs:
Default Re: Regular Expression Validation Puzzle

patricktr wrote:
> The character validation seems ok and it picks up when there is less that 5
> chars, but the max parameters doesn't seem to work at all - any ideas?


The problem is the +. Also, you should stop using ereg, as it is being
removed from PHP 6. Use the PCRE functions instead.

> PS. Is there a routine that strips out more than one space between words, e.g
> if someone entered 'John Smith', it would return 'John Smith'?,


This will do the validation for you, and strip out extra whitespace at
the same time:

$name = trim(preg_replace('/\s+/', ' ', $_POST['contact_name']));
if (!preg_match("/^[-a-z'\s]{5,10}$/i", $name)) {
$errors[] = 'Enter valid contact name';
}

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Reply With Quote