Make sure the list is comma seperated

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
silvercover
Forum Newbie
Posts: 10
Joined: Thu Sep 20, 2007 10:17 am

Make sure the list is comma seperated

Post 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.
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: Make sure the list is comma seperated

Post 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.
Post Reply