THANKS ROY!
Apologies for being slow to acknowledge your reply.
I goofed on first testing your code but then on inspection cleared that up and find that your regex does exactly as expected and is what I wanted, simply, and effectively,
Although I would like to get the hyphen included with the permissible characters, and wonder whether it will require the escape backslash?
Thank you for your very kind condsideration of this hapless hacker!
Mike
I WROTE:
I have this regex in my simple perl script handling a html form:
unless ($FORM{'phone'} =~ /\s*\(*\)*\.*\d+\-*\s*/) {
...
the point of which is to disallow text in the field whilst allowing for various punctuation styles.
Hoping to avoid re-inventing the whole system, I'd like to be able to allow certain text, i.e. ext. or Ext.
Any ideas? thx, mike
YOU WROTE:
You want to list all the alternatives, separated by vertical bars. For individual character alternatives, you can create a character class (a list or range of characters inside square brackets).
For example:
/^(?:
()\d\s|
Eext\.)*$/
matches a series of (any combination of) only left-paren, right-paren, digits, whitespace, or Ext. or ext.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.