Limit user input to allowable comma delimited words with regular expression using javascript?

There's not really a good way to do this with regex, since regex doesn't really have a good way to handle "only allowed to enter a given word once" if there's no specific ordering required.

I would do a double attack on this. In your validation function, use a regex as well as a JavaScript hashtable to store words that have already been entered so as to prevent duplicates from being entered. My two cents while having a sip of coffee.

I would suggest to split your requirement into several parts: 1) split the string using the str. Split(",") and get an array of strings 2) validate each element of the array using expression like "^(bacic|advanced|..)$" 3) use hashtable to put each array element into that and if element is added more than once then fail validation EDIT: Actualy in step 2 you can use another hashtable that will store all your words. It will be faster to check against hashtable than to run a regular expression.

Thanks for the helpful information, I think I will stick with what I have ^((basic|advanced)|admin|ectech)((,basic|,advanced)|,admin|,ectech){0,3}$ and allow duplicates – Marc Sep 3 '09 at 19:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions