Email validation using jQuery

后端 未结 30 2224
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 16:52

I\'m new to jQuery and was wondering how to use it to validate email addresses.

30条回答
  •  长发绾君心
    2020-11-22 17:24

    jQuery Function to Validate Email

    I really don’t like to use plugins, especially when my form only has one field that needs to be validated. I use this function and call it whenever I need to validate an email form field.

     function validateEmail($email) {
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
      return emailReg.test( $email );
    }
    

    and now to use this

    if( !validateEmail(emailaddress)) { /* do stuff here */ }
    

    Cheers!

提交回复
热议问题