I want to validate a field of string so that it only accept string that contains words with certain format.
Example accepted string:
- #key;
- #key1; #key2;#key3;
Example rejected string:
- key;
- %key1X @key2X$key3X
My regex:
\B(\#[a-zA-Z0-9_; ]+\b)(\;)
It seems my regex still accept a string as long as it has a word with valid format, while I only want it to be accepted if whole words are in the correct format.
Current example:
%key1; %key2 #keysz;#key3; @key4;
From the above Current Example still accepted because it contains #keysz;
and #key3;
while I want it to be rejected because there are %key1;
%key2
and @key4;
.
I've do some search and the closest I can found is this question, but it returns similar result as my current regex.
What did i do wrong in my regex? What is the right regex?
Sorry if this is dumb question but I'm a newbie in regex.