Question
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.
$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.
