Fellow monks, This unfortunatly is another regex question, I have tried searching for previous postings but it has yielded nothing. There are just too many postings regarding regex!
I want to check that a certain string has only letters (upper and lower) and optional commas.
- Commas should never be next to each other
- A comma at the end of the string is not allowed
- A comma at the start of the string is not allowed
Valid strings
- "notalot"
- "england,rugby"
- "chicken,egg,duck,feet"
Invalid Strings
- ",southampton"
- "bristol,"
- "iran, canada,france"
- ""
I tried the following but had no luck...
unless ($txt_collection =~ /([a-zA-Z]|([a-zA-Z],))+/) {
print "<font color=\"#ff0000\"><i>Incorrect format</i></font>";
$errors ++;
}
thanks for your time
-M
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.