in reply to Re^3: Tweak for my Perl Regex that screens for digits only
in thread Tweak for my Perl Regex that screens for digits only

Thanks for your reply--
I only meant to say that I'm not trying to validate that the submitted numbers are in fact a phone number.
You are correct, the "regex" I hacked up does not do what I thought it did. I did not test sufficient possibilites. Thanks for pointing that out.
Clearly I needed even more assistance than I asked for.
It's been something of a ,necessary) game deterring the spammers. I don't want to deter the legit posters with too many hurdles, and yet make it too much work for the spammers to be working my forms.
The testing I could think of indicates Roy's regex will allow whatever numbers are entered but no text other than the ext.
thx Mike
  • Comment on Re^4: Tweak for my Perl Regex that screens for digits only

Replies are listed 'Best First'.
Re^5: Tweak for my Perl Regex that screens for digits only
by ikegami (Patriarch) on Jan 25, 2006 at 20:49 UTC

    Maybe you should consider a statistical approach.

    You could use an absolute tolerance:

    my $good_chars = $FORM{'phone'} =~ tr/-()0-9. //; $good_chars += 3 if $FORM{'phone'} =~ /ext/i; if (length($FORM{'phone'} - $good_chars) > 4) { # Accept <= 4 bad # Bad phone number! ... }

    or a relative tolerance:

    my $good_chars = $FORM{'phone'}) =~ tr/-()0-9. //; $good_chars += 3 if $FORM{'phone'} =~ /ext/i; if ($good_chars / length($FORM{'phone'} < 0.80) { # Accept <= 20% bad # Bad phone number! ... }

    It would probably be more reliable than trying to find out all the valid characters.