jeudi 19 novembre 2020

Javascript Module Pattern not working as expected

When I write the following in Webstorm, it does not work. I get "function name expected." Any help is greatly appreciated. I'm using the book "The Principles of Object-Oriented Javascript," page 81 as my guide.

var validator = (function ()
{
    //source: https://www.w3resource.com/javascript/form/email-validation.php
    var EMAIL_PATTERN = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;

    return
    {
        validateEmail: function(email)
        {
            return EMAIL_PATTERN.test(email);
        }
    };
}());

console.log(validator.validateEmail("whatever@somewhere.com"));

Aucun commentaire:

Enregistrer un commentaire