Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:
I'm in need of a bit of help with this.
I'm trying to work out a regular expression for untainting data passed through a form.
Here's what I have:
#!/usr/bin/perl -w use strict; my $x = 'Ms a smith jr'; print "Name valid\n" if $x =~ m/^(\s+)?(M(s|rs?|iss)\.?)?\s+([A-Z]+)(\ +.)?(\s+)([A-Z]+)(\s+)?([A-Z]+)?$/i;
The part that has me wondering is checking for Mr/Mrs/Ms/Miss. Originally I had something along the lines of: (M(r?s?|iss)) which worked for all the 4 salutation cases, but that matched 'M' by itself as well.
My question is this: is there a way to check for this that is cleaner than the mess I have there now? I think I've taken in to account all (American) salutations ( if anyone does even use those on web forms ) and Jr's, III's, etc...
Thanks in advance!
There is no emoticon for what I'm feeling now.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Untainting name data from form
by chromatic (Archbishop) on Sep 24, 2002 at 23:56 UTC | |
Re: Untainting name data from form
by sauoq (Abbot) on Sep 25, 2002 at 00:45 UTC | |
by rob_au (Abbot) on Sep 25, 2002 at 04:27 UTC | |
Re: Untainting name data from form
by dws (Chancellor) on Sep 25, 2002 at 00:49 UTC | |
Re: Untainting name data from form
by Enlil (Parson) on Sep 25, 2002 at 00:40 UTC | |
Re: Untainting name data from form
by Popcorn Dave (Abbot) on Sep 25, 2002 at 01:22 UTC | |
Re: Untainting name data from form
by Fastolfe (Vicar) on Sep 25, 2002 at 16:25 UTC |