validate email with regex jquery

前端 未结 5 775
名媛妹妹
名媛妹妹 2020-12-06 18:09

referring to this issue:

how can I set a minimum length for a field with jquery?

5条回答
  •  忘掉有多难
    2020-12-06 18:55

    You probably want to use a regex like the one described here to check the format. When the form's submitted, run the following test on each field:

    var userinput = $(this).val();
    var pattern = /^\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
    
    if(!pattern.test(userinput))
    {
      alert('not a valid e-mail address');
    }​
    

提交回复
热议问题