Reputation: 1728
I'm trying to validate a field with comma separated list of strings(particular form) or empty. I can't use split.
I've managed to have a regular exp for a single string.
I just want to implement comma separation(with spaces before and after , may be) or having empty string. If it is not empty it must have the particular string format. Here if more than one string is entered then it should use comma.
The string format is
^([a-z_\.\-])+\@(([a-z\-])+\.)+([a-z]{2,4})+$
Pls help me to add comma separation and a whole empty string. Thanks
Upvotes: 0
Views: 3202
Reputation: 3171
Try this expression
/^$|^([a-z_\.\-])+\@(([a-z\-])+\.)+([a-z]{2,4})+(\s*,\s*([a-z_\.\-])+\@(([a-z\-])+\.)+([a-z]{2,4})+)*$/
The pattern is ^$|^string(,string)*$
Upvotes: 3