locked
how to check @ and .com inside input email RRS feed

  • Question

  • User-1634604574 posted

    how to check @ and .com inside input email in jquery

    Sunday, November 11, 2018 9:21 AM

Answers

  • User-1038772411 posted

    Put validation email function into separate javascript file and call javascript file into your html code.

    Example:
    emailvalidation.js  // js file

    function IsValidEmail(email)
    {
    var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return expr.test(email);
    };
    
    function ValidateEmail()
    {
    var email = document.getElementById("txtEmail").value;
    if (!IsValidEmail(email)) {
    alert("Invalid email address.");
    }
    
    else
    {
    alert("Valid email address.");
    }
    }
    
    

    EmailValidation.cshtml

    <script src="~/js/emailvalidation.js"></script>
    
    <input type="text" id="txtEmail" />
    <input type="button" id="btnValidate" value="Validate Email" onclick="ValidateEmail()" />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 12, 2018 6:31 AM

All replies

  • User1120430333 posted

    https://gist.github.com/fakiolinho/5438830

    Bing and Google have plenty of examples  you can search for and implement one of them

    Sunday, November 11, 2018 11:15 AM
  • User-1634604574 posted

    but i have error with that code can tell me why?

    Sunday, November 11, 2018 11:21 AM
  • User-1634604574 posted

    i have this code for checking valid error on this symbol @

    function isEmailValid(emailAdress) {
    var EMAIL_REGEXP = new RegExp('^[a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,15})$', 'i');
    return EMAIL_REGEXP.test(emailAdress)
    }

    can anyone help me?

    Sunday, November 11, 2018 11:39 AM
  • User421742879 posted

    Try

    function validateEmail(email) {
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(String(email).toLowerCase());
    }
    Sunday, November 11, 2018 3:35 PM
  • User-1634604574 posted

    also i have error

    Sunday, November 11, 2018 9:08 PM
  • User-1038772411 posted

    Put validation email function into separate javascript file and call javascript file into your html code.

    Example:
    emailvalidation.js  // js file

    function IsValidEmail(email)
    {
    var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return expr.test(email);
    };
    
    function ValidateEmail()
    {
    var email = document.getElementById("txtEmail").value;
    if (!IsValidEmail(email)) {
    alert("Invalid email address.");
    }
    
    else
    {
    alert("Valid email address.");
    }
    }
    
    

    EmailValidation.cshtml

    <script src="~/js/emailvalidation.js"></script>
    
    <input type="text" id="txtEmail" />
    <input type="button" id="btnValidate" value="Validate Email" onclick="ValidateEmail()" />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 12, 2018 6:31 AM
  • User1520731567 posted

    Hi zhyanadil.it@gmail.com,

    how to check @ and .com inside input email

    To check @ and .com,you could code like:

    ^([\w-\.]+)@(([\w-]+\.com)+)$

    Like the picture:

    You could try your regex according to your need in this website:

    https://regex101.com/

    Best Regards.

    Yuki Tao

    Monday, November 12, 2018 8:40 AM
  • User1520731567 posted

    And I suggest you could refer to this link about Regular expression:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

    Best Regards.

    Yuki Tao

    Monday, November 12, 2018 8:44 AM