1

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 same 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.

Community
  • 1
  • 1
rachel
  • 13
  • 3

2 Answers2

3

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
}
James Allardice
  • 164,175
  • 21
  • 332
  • 312
1

Convert both in lover case by and than compare

if(password.toLowerCase() == username.toLowerCase())
{
    //sucess
}
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263