Jquery RegEx Validation

前端 未结 5 495
情书的邮戳
情书的邮戳 2020-12-31 10:52

I am wanting to check if an input field has the attribute \"pattern\" and if so, preform a regex check aganst said pattern.I know this is already done by HTML5, but I am wan

5条回答
  •  旧时难觅i
    2020-12-31 11:45

    Below is the proper way to validate a text-box based on a regular Expression using Jquery in MVC. Please note that this expression is made to validate multi email addresses in one string:

          var emailReg = new RegExp(/^([A-Z0-9.%+-]+@@[A-Z0-9.-]+.[A-Z]{2,6})*([,;][\s]*([A-Z0-9.%+-]+@@[A-Z0-9.-]+.[A-Z]{2,6}))*$/i);
          var emailText = $('#email').val();
    
          if (!emailReg.test(emailText)) {
              alert('Wrong Email Address\Addresses format! Please reEnter correct format');
                return false;
            }
        }
    

提交回复
热议问题