Hi i have a special java code for input strings like (For only first character upper and the rest in lower case):
Code:
<script type="text/javascript">
String.prototype.toCapitalCase = function() {
var re = /\s/;
var words = this.split(re);
re = /(\S)(\S+)/;
for (i = words.length - 1; i >= 0; i--) {
re.exec(words[i]);
words[i] = RegExp.$1.toUpperCase()
+ RegExp.$2.toLowerCase();
}
return words.join(' ');
}
</script>
And in HTML i have it like
Code:
<form name="formname">
<input type="text" name="name" onblur="javascript:this.value=this.value.toCapitalCase();">
</form>
I have a question how can i add there a check for special characters and spaces and immediatelly remove them? I had something like this:
Code:
function clearText() {
document.formname.name.value=filterNum(document.formname.name.value)
function filterNum(str) {
re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
return str.replace(re, "");
}
}
But i dont know how to make it work in <input> and this is also without spaces check ... Thx for help