문제

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)

다른 팁

It seems likely that username is not in the scope of the expression. You could do document.username = username and use document.username in the expression.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top