2011-07-22 168 views
1

可能重複:
javascript compare strings without being case sensitive.檢查不區分大小寫jQuery中

我有兩個字段。我需要檢查兩個字段是否包含相同的值。如果相同的值,則會引發警報。

我正在使用驗證引擎jQuery。

我有一個書面的功能,如:

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

例子:

[email protected] and [email protected] // shows error message 
[email protected] and [email protected] // no error message is shown 

請誰能幫助。這兩個值都是用戶輸入。

回答

3

使用toLowerCase()功能。這將您的字符串轉換爲小寫字符,則比較會是否有在不同的情況下原本返回true:

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

在情人情況下都轉換比比較

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