Check for case insensitivity in jQuery [duplicate]
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
}
精彩评论