Page 1 of 1

Make sure the list is comma seperated

Posted: Thu Jul 22, 2010 7:33 am
by silvercover
Hi,

How can I make sure that the entered list is comma separated correctly? It must be a,b,c,... and not a,,b,c,-,d with other wrong separators or some thing similar.

the right format for me is String1,String2,String3,...

Thanks in Advance.

Re: Make sure the list is comma seperated

Posted: Thu Jul 22, 2010 9:05 am
by dejvos
What about that?

Code: Select all

function checkList($list){
$x = explode(",",$list);
foreach($x as $y){
if(empty($y) || 
preg_match('/[-_;]/',$y)) // Put all needed separators into regular expression.
return false;
}

return true
}
But I am not sure if i get your point. This solution is very easy and stupid.