After a quick research on the Stackoverflow, I wasn't able to find any solution for the multiple email validation using regex (split JS function is not applicable, but some reason back-end of the application waits for a string with emails separated by ;
).
Here are the requirements:
- Emails should be validated using the following rule:
[A-Za-z0-9\._%-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,4}
- Regex should accept
;
sign as a separator - Emails can be written on multiple lines, finishing with
;
- Regex may accept the end of the line as
;
I come up with this solution:
^[A-Za-z0-9\._%-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,4}(?:[;][A-Za-z0-9\._%-]+@[A-Za-z0-9\.-]+\.[A-Za-z]{2,4}?)*
but it doesn't work for point #3-4
So here are cases that are OK:
1. [email protected];[email protected] 2. [email protected];[email protected]; 3. [email protected]; [email protected]; [email protected];
Here are cases that are definetely NOT OK:
1. [email protected] [email protected] 2. [email protected], 3. [email protected] [email protected]
All sort of help will be appreciated