Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, January 12, 2011

Special Character check through javascript

//The IndexOf method can be used to check if one character is inside of another. For example, suppose you want to check an email address to see if it contains the @ character. If it doesn't you can tell the user that it's an invalid email address.



script type="text/javascript" language ="javascript" >

function checkSpecialCharacters() {

var str = "'!#$%^&;*()";
var txtUserId = document.getElementById('txtUserId').value;
var txtPassword = document.getElementById('txtPassword').value;
var txt = txtUserId + txtPassword;

for (var i = 0; i < str.length; i++) { var char1 = str.substr(i, 1) if (txt.indexOf(char1) > -1) {
alert('special character(s) are not allowed in loginid/password');
//alert(obj.getMessage(196));
return false;
}
}
}
/script>

No comments:

Post a Comment