in reply to Re^2: Tweak for my Perl Regex that screens for digits only
in thread Tweak for my Perl Regex that screens for digits only
When text or letters are input the regex generates an error msg,Disallowing is a form of validation. And your regexp doesn't disallow what you claim it disallows. If there's a digit anywhere in the string, it doesn't generate an error message.
foreach ( '416-967-1111', 'I had 2 glasses of orange juice with my breakfast', 'I had two glasses of orange juice with my breakfast', ) { unless (/\s*\(*\)*\.*\d+\-*\s*/) { print("error message\n"); } else { print("no error message\n"); } }
outputs
no error message no error message error message
rather than the desired
no error message error message error message
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Tweak for my Perl Regex that screens for digits only
by hackermike (Novice) on Jan 25, 2006 at 20:34 UTC | |
by ikegami (Patriarch) on Jan 25, 2006 at 20:49 UTC |