Ad

You can also create RegExp for matching whole email without the need to iterate all chars.

P.S. I got ReferenceError that Test is not defined, thus failed tests

Code
Diff
  • const parse = (value = '') => value.split("").every(letter => new RegExp('[A-Za-z0-9.@]').test(letter));
    • const parse = (value = '') => {
    • // if valid email, return true, else return false
    • let validEmail;
    • const validCharacters = ["a","A", "b","B","c","C","d","D","e","E","f","F",
    • "g","G","h","H","i","I","j","J","k","K","l","L",
    • "m","M","n","N","o","O","p","P","q","Q","r","R",
    • "s","S","t","T","u","U","v","V","w","W","x","X",
    • "y","Y","z","Z","0","1","2","3","4","5","6","7",
    • "8","9","@","."]
    • const emailArray = value.split("");
    • for (let i = 0; i < emailArray.length; i++) {
    • if (validCharacters.includes(value[i]) == true) {
    • validEmail = true;
    • }
    • else {
    • validEmail = false;
    • break;
    • }
    • }
    • return validEmail;
    • }
    • const parse = (value = '') => value.split("").every(letter => new RegExp('[A-Za-z0-9.@]').test(letter));