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

Simple validation of a incomming contact name ..

$contact_name = trim($_POST['contact_name']);
if (!ereg("^([a-zA-Z \'-]+){5,10}$", $contact_name))
{ $errors [] = 'Enter valid contact name'; }

As you can see the name must be u/l case alpha or space, apostophe or hyphen
(I think that is all a name can be) and must be at least 5 chars and no more
than 10 (just testing).

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?

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'?,
Thanks.




Reply With Quote
Sponsored Links