Gerald Wheeler am Dienstag, 14. Februar 2006 21.03:
> I am trying to allow input of a person's first and last name in one form
> field, nothing more, nothing less
>
> There should be only one uppercase A-Z character followed by one or
> more lowercase a-z characters followed by one space followed by one
> uppercase A-Z character followed by one or more lowercase a-z
> characters, nothing more.
>
> have tried this which does not work:  /^[A-Z a-z]\s+[A-Z a-z]{1,15}$/

It's not enough restrictive. According to your exact description, it should be 
(untested):

/^[A-Z][a-z]+ [A-Z][a-z]+$/

Of course, you can replace the '+' by {min,max}.

Further, for userfriendliness, you could allow other whitespace, and more 
between the words, and additonally around them, and trim them away 
*afterwards*:

my $userinput=get_from_request();

if (/^\s*([A-Z][a-z])+\s*([A-Z][a-z])+\s*$/) { 
  # input is ok, so now we format:
  my $formatted="$1 $2";
  do_something_with($formatted);
}

hth,
Hans

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to