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

Posted by Marc on Stack Overflow See other posts from Stack Overflow or by Marc
Published on 2009-09-03T19:20:18Z Indexed on 2010/03/23 13:03 UTC
Read the original article Hit count: 670

Filed under:
|
|
|

I want to force the user to enter any combination of the following words. the words need to be comma delimited and no comma at the beginning or end of the string the user should only be able to enter one of each word.

Examples

admin
basic,ectech
admin,ectech,advanced
basic,advanced,admin,ectech

my attempt

^((basic|advanced)|admin|ectech)((,basic|,advanced)|,admin|,ectech){0,2}$

Thanks Marc

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex