开发者

javascript regex for validating email list with ASP MVC 2 data annotations

开发者 https://www.devze.com 2023-01-13 18:31 出处:网络
I am trying to use ASP MVC 2 data annotations to validate a semicolon delimited list of email addresses on the client side.The regex below works on the server side but doesn\'t work with the javascrip

I am trying to use ASP MVC 2 data annotations to validate a semicolon delimited list of email addresses on the client side. The regex below works on the server side but doesn't work with the javascript because javascript regular expressions don't support conditionals.

^([A-Za-z0-9_\\+\\-]+(\\.[A-Za-z0-9_\\+\\-]+)*@[A-Za-z0-9-]开发者_StackOverflow社区+(\\.[A-Za-z0-9]+)*\\.([A-Za-z]{2,4})(?(?=.);[ ]*|))+$

Is there a way to require that the email address is followed by a semicolon only if it is followed by another email address without using a conditional? Thanks.


if you need only this to alow this -

foo@bar.cz; bar@foo.cz

then regexp is

"^(([A-Za-z0-9_\+\-]+\.)*[A-Za-z0-9_\+\-]+@([A-Za-z0-9]+\.)+([A-Za-z]{2,4})(\s*(;)\s*))*([A-Za-z0-9_\+\-]+\.)*[A-Za-z0-9_\+\-]+@([A-Za-z0-9]+\.)+([A-Za-z]{2,4})$"
0

精彩评论

暂无评论...
验证码 换一张
取 消