
November 7th, 2009, 12:24 PM
|
 |
Contributing User
|
|
|
|
Quote: | Originally Posted by gibatul Hi i have a special java code for input strings like:
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 |
You don't want to strip out every character that way. You want to only allow certain characters.
Apparently you only want CAPITAL LETTERS in your input field, and nothing more.
Code:
var re = /^([A-Z]+)$/;
str.replace(re,"");
Edit: Or with spaces allowed,
Code:
var re = /^([A-Z\s]+)$/;
str.replace(re,"");
__________________
- The Wise Guy
Last edited by s-p-n : November 7th, 2009 at 12:34 PM.
|