need regular expression for comma delimited list

B

billsahiker

I cannot get anything to validate a comma delimited list of stock
symbols, like "IBM, MSFT,INTC). symbols are alphanumeric with a maxium
length of 5. I want to block multiple, adjacent commas, and allow up
to two blank spaces between symbols.
The following did not work:
(\w{1,5}(, *)?)*
 
N

noagbodjivictor

(\w{1,5}(, *)?)*

Maybe (\w{1,5}(,)?(\s+)?)* ?
You need a regular expression validator. I used to know one, but...
 
G

Georgi Naumov

Hi.
I hope this function will help you.
/**
* @author
* Georgi Naumov
*/
function testString(aValue)
{
/****
* This pattern will match
* only spaces between stock
* symbols and commas. If you
* use the \s shorthand
* character class this will
* be match "any white space".
*/
var re = /^\u0020*\w{1,5}\u0020*(?:,\u0020*\w{1,5}\u0020*)*$/;
return aValue.match(re) != null;
}
Best regards.
 
G

Georgi Naumov

Hi.
I hope this function will help you.
/**
* @author
* Georgi Naumov
*/
function testString(aValue)
{
/****
* This pattern will match
* only spaces between stock
* symbols and commas. If you
* use the \s shorthand
* character class this will
* be match "any white space".
*/
var re = /^\u0020*\w{1,5}\u0020*(?:,\u0020*\w{1,5}\u0020*)*$/;
return aValue.match(re) != null;}

Best regards.
I fixed the pattern. Because my english is not very well
i was miss "and allow up
to two blank spaces between symbols".
^\u0020*\w{1,5}\u0020*(?:,\u0020*\w{1,5}\u0020*)*$
This pattern will match "between 0 and unlimited numbers
of spaces". This is correct pattern:

^(?:\u0020{1,2})?\w{1,5}(?:\u0020{1,2})?(?:,(?:\u0020{1,2})?\w{1,5}(?:
\u0020{1,2})?)*$
 
B

billsahiker

- Hide quoted text -
- Show quoted text -
Hi.
I hope this function will help you.
/**
* @author
* Georgi Naumov
*/
function testString(aValue)
{
/****
* This pattern will match
* only spaces between stock
* symbols and commas. If you
* use the \s shorthand
* character class this will
* be match "any white space".
*/
var re = /^\u0020*\w{1,5}\u0020*(?:,\u0020*\w{1,5}\u0020*)*$/;
return aValue.match(re) != null;}
Best regards.
On May 30, 10:48 am, Duncan Booth <[email protected]>
wrote:

Thank you. It works.

I fixed the pattern. Because my english is not very well
i was miss "and allow up
to two blank spaces between symbols".
^\u0020*\w{1,5}\u0020*(?:,\u0020*\w{1,5}\u0020*)*$
This pattern will match "between 0 and unlimited numbers
of spaces". This is correct pattern:

^(?:\u0020{1,2})?\w{1,5}(?:\u0020{1,2})?(?:,(?:\u0020{1,2})?\w{1,5}
(?:
\u0020{1,2})?)*$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top