[英]Prevent user from entering certain word in textarea
so I have a site and I would like my users to not be able to words like ".com" or ".net" etc. If they do enter it then i just want it to replace with a space. 所以我有一个网站,我希望我的用户无法输入“ .com”或“ .net”等字样。如果他们输入了该字,那么我只希望它用空格代替。 So far I have toe javascript code for if users were to type in any html code into the text area, then it would replace it with a space, I want the same to to happen if they were to type out those certain words.
到目前为止,我已经有了一个javascript代码,如果用户要在文本区域中键入任何html代码,那么它将用一个空格替换它,如果他们要键入这些特定的单词,我希望同样发生。
function stoppedTyping(){
if(this.value.length > 0) {
document.getElementById('post_btn').disabled = false;
} else {
document.getElementById('post_btn').disabled = true;
}
var re = /(<([^>]+)>)/gi;
for (i=0; i < arguments.length; i++){
arguments[i].value=arguments[i].value.replace(re, "");
}
var se = ".com";
for(a=0; a < arguments.length; a++){
arguments[a].value=arguments[a].value.replace(se, "");
}
}
The last var se.... is my attempt to try and replace the word. 最后一个var se ....是我尝试替换的单词。 But it isn't working.
但这不起作用。 Thanks in advance!
提前致谢!
For real-time replacements, I would use onkeyup
to listen to whenever the user finishes pressing a key. 对于实时替换,每当用户完成按键操作时,我都会使用
onkeyup
进行监听。 Here's a JSFiddle demo: http://jsfiddle.net/kLTq5/1/ 这是一个JSFiddle演示: http : //jsfiddle.net/kLTq5/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.