AngularJS - Remove leading and trailing whitespace from input-box using regex

前端 未结 2 903
一生所求
一生所求 2020-11-29 13:23

I am writing a regular expression(regex) for adding multiple email ids in an input box with following conditions:

  1. Multiple email ids must be separated with com
2条回答
  •  抹茶落季
    2020-11-29 13:50

    Do you want leading/trailing spaces allowed on the whole string, or around each individual address?

    For the former your regex should be

    /^(\s*([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([,.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+\s*)*$/
    

    and for the latter

    /^(\s*([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25}\s*)+([,.](\s*([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+\s*)*$/
    

提交回复
热议问题