what i came up with is not that great so i thought i would ask here.
Here is what i have
Code:
function chk_validchars()
{
var field=document.getElementById("mytext").innerHTML;
var newfield=str.replace("''''''''''","invalid character");
document.getElementById("mytext").innerHTML=newfield;
}
</script>
Here is the out put (certainly not what i want) I thought maybe it would at least put invalid character on every occurance of the length of ' but it just does it once.
Prefered would be either replace with null or even something like this
Quote:
'''''''i am an Idiot''''''i am an idiot'''''''''''''''''''''''''hello
lol sorry just had to be mean on that one, but seriously if we could replace multiple chars of 4 or more like '''''' or ............. with some kind of text like invalid would be great.
120 chars required is only three lines of short text and hard to believe people cant come up with that.
you could try this, which replaces 4 or more of any consecutively repeated character with "invalid character"...
Code:
var str=document.getElementById("mytext").innerHTML;
var newfield=str.replace(/(\w)\1{3,}/g," invalid character ");
document.getElementById("mytext").innerHTML=newfield;
found this expression and it does seem to work but it puts invalid character a bunch of times rather than just once, which i guess is ok but i would like the option of just once if possible.
Code:
var str=document.getElementById("mytext").innerHTML;
var newfield=str.replace(/[^\w\s]|(.)(?=\1{3,})/gi," invalid character ");
document.getElementById("mytext").innerHTML=newfield;
The one you found will replace anything that isn't alphanumeric or space.
__________________ ^_^
If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
* The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
<div id = "mytext">
</div>
<script type = "text/javascript">
var field = ' """"""i am an Idiot"""""i am an idiot"""""""hello '
if(/(.)\1{2,}/i.test(field)) { //string contains at least 3 identical consecutive characters (case insenstive)
alert ("Three in a row in the string!");
field = field.replace(/(.)\1{3,}/gi,"");
document.getElementById("mytext").innerHTML = field;
}
</script>
But that does not stop qwertyuiopqwertyuiopwertyuipqwertyuipqwertyuiop
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
thanks phil, that was awesome, perfect... that will at least stop them from the repeat char input... Peace very cool... If i give you another thanks i would, reply and i will give you a bonus thanks if you want.
thanks phil, that was awesome, perfect... that will at least stop them from the repeat char input... Peace very cool... If i give you another thanks i would, reply and i will give you a bonus thanks if you want.
only one thing, i think this should be
field = str.replace(/(.)\1{3,}/gi,"");
not
field = field.replace(/(.)\1{3,}/gi,"");
No. Why do you say that?
You can only give one "Thanks" per post, but you can add to my rep if you want!
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
sorry my eyes were playing tricks on me i convinced myself the command was str.replace instead of replace.. oops Its all good, just fyi i had to add an if statment before that process to check for null or value or even space because it was seeing the empty textarea as repeated chars. So it would cause the alert to go off prematurely.
sorry my eyes were playing tricks on me i convinced myself the command was str.replace instead of replace.. oops Its all good, just fyi i had to add an if statment before that process to check for null or value or even space because it was seeing the empty textarea as repeated chars. So it would cause the alert to go off prematurely.
Nice job thanks
Huh? Three consecutive spaces, yes. No spaces or an empty field - no.
Note that the value of a form field can never be null. Only "" (blank).
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.