-3

i use front page to create website for my education in school, so when i run my website this error showed to me ligne:28 character:1 erreur: the value of the << indexOf >> property is null or not defined, not an object function

function verif() {
    var a = f.T1.value;
    var b = f.T2.value;
    var c = f.T3.value;
    var lettres = /^[A-Za-z]+$/;
    var chiffres = /^[0-9]+$/;
    var lett = a.charAt(0) + a.charAt(1);
    var chiff = a.charAt(2) + a.charAt(3);
    if (!(lett.match(lettres)) && !(chiff.match(chiffres))) {
        alert("2 premier lettres alphabet et 2 autres chiffres");
        return false;
    }
    if (!(b.match(lettres)) || b == "") {
        alert("chaine alphabetique non vide");
        return false;
    }
    if (!(c.match(lettres)) || c == "") {
        alert("chaine alphabetique non vide 2");
        return false;
    }
    var d = f.T4.value;
    if (indexOf('@', d) == -1) {
        alert("email invalid");
        return false;

    }
    v1 = indexOf('@', d);
    ch = substring(0, v1 - 1);
    if (!(isNaN(ch))) {
        alert("email invalid");
        return false;
    }
    if (indexOf('.', d) == -1) {
        alert("email invalid");
        return false;
    }
    p2 = indexOf('.', ch);
    ch1 = substring(p2 + 1, length(ch) - 1);
    if (!(isNaN(ch1))) {
        alert("email invalid");
        return false;
    }
    p3 = indexOf('@', d);
    p4 = indexOf('.', d);
    v1 = substring(p3 + 1, p4 - 1);
    if (!(isNaN(v1))) {
        alert("email invalid");
        return false;
    }
}
Raeesaa
  • 3,267
  • 2
  • 22
  • 44

2 Answers2

1

You should be calling it on an array. Replace instances where you call it like:

indexOf("something", array)

with:

array.indexOf("something")
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46
  • it's a string –  May 18 '18 at 16:08
  • @whitecoder It works the same for both. Also it appears you are trying to do something for HTML in which a parser would be better. See this time honored answer: https://stackoverflow.com/a/1732454/4848801 – Ryan Schaefer May 18 '18 at 16:09
  • i want to return the positionsof '@' in T4 to verify if the email is valid –  May 18 '18 at 16:11
  • @whitecode do you want find position or do you want to find if string contains '@' ? – BeeBee8 May 18 '18 at 16:17
  • exemple : stackoverflow@exemple.com so if i want to copy 'example' 'stackoverflow' 'com' to verify if it is a string or no how can i do it ? –  May 18 '18 at 16:18
0

indexOf is a method which you can use on a string/array. So for e.g

var myString = "string";
console.log(myString.indexOf('s')); // returns 0

Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.

BeeBee8
  • 2,944
  • 1
  • 27
  • 39
  • how can i return the position in string ? –  May 18 '18 at 16:10
  • @whitecoder , it will return position in string when you operate it on any string. I have shown e.g in my answer that if you find 's' in 'string' it will return 0 as 's' is present at the start – BeeBee8 May 18 '18 at 16:13
  • exemple : stackoverflow@exemple.com so if i want to copy 'example' 'stackoverflow' 'com' to verify if it is a string or no how can i do it ? –  May 18 '18 at 16:17