开发者

to convert alpha numeric string to a lower case in javascript

I am reading a text field, and converting that value to Lower case and comparing to the array of words, if it matches it throws error.

But the problem is when we enter a text as a Alpha Numeric value, then I am not able to convert Lower case letters and getting the Run Time error as "Object is Not Defined"

if(streetAddress != null){
    for(var k=0; k<notValidPostalChars.length; k++){

        var secondWord = notValidPostalChars[k];

        if (streetAddress.toLowerCase().startsWith(stopWord.toLowerCase())) {
            alert("Invalid Error Message");
            document.getElementById("address").focus();
   开发者_JAVA百科     return false;
        }

    }
}

In the above Example, streetAddress may contain the Alpha Numeric as well and it might be in the Lower case or Upper case letters.

This will be entered by the End users and notValidPostalChars is an Array consisting of all the Pre defined Words with UPPER CASE letters


Maybe stopWord is not defined?

var secondWord = notValidPostalChars[k];
if (streetAddress.toLowerCase().startsWith(stopWord.toLowerCase())) {
//                                         ^did you mean secondWord?
   alert("Not invalid mesage");
//       ^ did you mean 'invalid message / not a valid message'?
   document.getElementById("address").focus();
   return false;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜