0

Hi i have some functions in JavaScript for a contact form, but Dreamweaver cs6 is showing syntax error. Can someone please help me? The first and second (let) syntax give an error as well as the final class user.

var fields = {};
document.addEventListener("DOMContentLoaded", function() {
fields.name = document.getElementById('name');
fields.email = document.getElementById('email');
fields.message = document.getElementById('message');
})

function isNotEmpty(value) {
if (value == null || typeof value == 'undefined' ) return false;
return (value.length > 0);
}

function isEmail(email) {
let regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
return regex.test(String(email).toLowerCase());
}

function fieldValidation(field, validationFunction) {
if (field == null) return false;

let isFieldValid = validationFunction(field.value)
if (!isFieldValid) {
field.className = 'placeholderRed';
} else {
field.className = '';
}

return isFieldValid;
} 

function isValid() {
var valid = true;

valid &= fieldValidation(fields.name, isNotEmpty);
valid &= fieldValidation(fields.email, isNotEmpty);
valid &= fieldValidation(fields.message, isNotEmpty);
valid &= fieldValidation(fields.email, isEmail);
return valid;
}

class User {
constructor(name, email, message) {
this.name = name;
this.email = email;
this.message = message;
 }
}
7
  • 1
    Look at the highlighting of the post. That newline in your regex is not helping at all. Commented Jan 29, 2020 at 19:39
  • I think some character escaping might also be needed in the regex Commented Jan 29, 2020 at 19:49
  • Thank you, can you help me with an example of how i could do the character escaping please? Commented Jan 29, 2020 at 20:00
  • @BenGali The place I originally thought might need it actually doesn't. But the part where you do (?:.[a- if you expect that to match a literal . (dot), then you'll need to escape that like (?:\.[a-. Otherwise, it will match any character Commented Jan 29, 2020 at 20:06
  • Thanks @Patrick Q i have added that it still says syntax error on line 14. however if i replace let with var to create an instance of regex. it changes to next place i have used let. it seems this syntax is casuing error in cs6 only. i will test the code now with the changes you suggested. Commented Jan 29, 2020 at 20:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.