it would be far easier to change the values to lower case
example
<input type="text" name="lowercaps" onChange="javascript:this.value=this.value.toLowerCase();"> Just a suggestion: faq183-874
Thanks, but I want the inputter to know they need to use lowercase letters.. Changing it my go unnoticed, and then cause further problems when they attempt to sign in.
try this
<html>
<head>
<SCRIPT>
function checkCase()
{
str = document.form1.lowercaps.value
// value to test
strLen = document.form1.lowercaps.value.length
// length for loop
for(i=0; i <= strLen-1; i++) {
if (str.charAt(i) < "a" || str.charAt(i) > "z" {
// test for a character a to z
// for upper cahnge to A to Z
alert("Only lower case values are valid!"
return
}
}
}
</SCRIPT>
</head>
<body>
<form name="form1">
<input type="text" name="lowercaps" onBlur="return checkCase()">
</form>
</body>
</html> Just a suggestion: faq183-874
after looing at that nasty loop I don't know why I did it that way. much easier to use a regex. try this
str = document.form1.lowercaps.value
var patrn = /^[a-z]+$/;
if (!(patrn.test(str))) {
alert("invalid!"
return false;
Just a suggestion: faq183-874
use the select() function to select the contents of the field and the focus() function to focus on it.
document.form1.lowercaps.select();
document.form1.lowercaps.focus(); Just a suggestion: faq183-874
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.