javascript:验证在文本框中添加,删除和修改的字符数

时间:2014-06-03 06:00:29

标签: javascript

我想验证在文本框中添加,删除和修改的字符数。

以下是修改验证字符的代码:

function charModified(currentValue,actualValue) {
    var charModified=0;
    var iterationLength = Math.min(currentValue.length,actualValue.length);
    for(var j=0;j<iterationLength;j++) {
        if(currentValue.charAt(j)!=actualValue.charAt(j)) {
            charModified++;
        }

    }
    if(charModified>3) {
            alert("more than 3 charcters are modified ");
    }
     return charModified;

}

以下是验证字符AddedRemoved:

的代码
function charAddedRemoved(actualValueLength,currentValueLength) {
var numberOfCharcters = 0;

    if(actualValueLength>currentValueLength)    {
        numberOfCharcters = actualValueLength- currentValueLength;
    }
    if(currentValueLength>actualValueLength)    {
        numberOfCharcters = currentValueLength - actualValueLength;
    }
    if(numberOfCharcters>3) {
        alert("Added/Removed more than 3 Characters ");
    }
 }

0 个答案:

没有答案