javascript to validate email is not working RRS feed

  • Question

  • User1868852945 posted

    Here is a simple email validation function I got from a google search:

    var ret = validateEmail("badData");
    alert ("ret: " + ret);

    function validateEmail(email) {
    var re = /\S+@\S+\.\S+/;
    return re.test(email);

    When testing it, I get this error...

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: "\" is not valid at the start of a code block.  Only identifiers, keywords, comments, "(" and "{" are valid.

    Source Error:

    Line 796:
    Line 797:        function validateEmail(email) {
    Line 798:            var re = /\S+@\S+\.\S+/;
    Line 799:            return re.test(email);
    Line 800:        }

    If helpful, this is in a razor view page with <script src="~/js/jquery-2.1.3.min.js"></script>

    Thanks very much if someone can advise how to fix or a better way to validate proper email address format.

    Wednesday, April 10, 2019 4:40 PM