I'm currently using this plugin to perform live form validation GeekTantra
This is working well and is validating all of my form fields bar one.
I'm trying to see if a username entered into a field matches a value in an array and if it does return a 'username is already in use' message. The data is being collected using PHP, converted to lowercase and then written to a jquery array.
Checking that array using console.log(username)
shows :
["bob", "brian", "charlie", "mike", "dave", "simon", "lincoln", "reg", "bill"]
The rule I'm using is:
jQuery("#name").validate({
expression: "if ($.inArray(VAL.toLowerCase(), username)!==-1) return true; else return false;",
message: "username is already in use"
});
Yet I never seem to get the results expected. Looking at the array I can see reg is in use, but if I enter REG or reg etc in the form field, It doesn't match the array. If I enter Phil then I get told that is in use, when it's not.
What am I doing wrong ?
Thanks
UPDATE
This works.. why ?
expression: "if ($.inArray(VAL.toLowerCase(), username)<=-1) return true; else return false;",
i think its a syntax error
try to change=>
from--
if ($.inArray(VAL.toLowerCase(), username)!==-1)
to---
if ($.inArray(VAL.toLowerCase(), username)!=-1)