开发者

Check for case insensitivity in jQuery [duplicate]

开发者 https://www.devze.com 2023-03-22 10:33 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: javascript compare strings without being case sensitive.
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

javascript compare strings without being case sensitive.

I am having two fields. I need to check whether both the fields contain the same value. If the s开发者_StackOverflow社区ame value then a alert is raised.

I am using validation engine jQuery.

I have a written a function like:

function kkkk(field, rules,i,options){
    var password=field.val();
    var username = getValueUsingElementID('username');
    if(password==username){
        return options.allrules.NotEqual.alertText;
    }
}

Example:

sss2@ and sss2@ // shows error message
sss2@ and SSS2@ // no error message is shown

Please can anyone help. Both the values are user input.


Use the toLowerCase() function. That will convert your strings to all lower case characters, and the comparison will then return true whether or not there were differences in case originally:

if(password.toLowerCase() == username.toLowerCase()) {
   //Do stuff
}


Convert both in lover case by and than compare

if(password.toLowerCase() == username.toLowerCase())
{
    //sucess
}
0

精彩评论

暂无评论...
验证码 换一张
取 消