【发布时间】:2012-10-23 18:39:26
【问题描述】:
我想要一个脚本,它应该在文本字段中输入空格时提醒用户。我认为它需要 javascript。我正在编写一个脚本,我不希望用户在其中输入空格在文本字段中。
【问题讨论】:
-
到目前为止你做了什么?你被什么困住了?
-
在我创建的注册表单中,我不希望在用户名中输入空格
标签: javascript textbox space prompt
我想要一个脚本,它应该在文本字段中输入空格时提醒用户。我认为它需要 javascript。我正在编写一个脚本,我不希望用户在其中输入空格在文本字段中。
【问题讨论】:
标签: javascript textbox space prompt
以下功能起作用
$returnValue = preg_match('/[^a-z^A-Z^0-9]/', $str, $matches);
if ($returnValue==1)
{
alert("spaces & symbols are not allowed");
}
注意:不仅限制空格,还限制符号。
【讨论】:
使用字符串的match()方法
<script type="text/javascript">
function checkForm()
{
var textb=document.getElementById("textbox1").value;
if(textb.match(' ')){
alert('Spaces not allowed!');
return false;
}
}
【讨论】:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$("textarea").keypress( function(e) {
if (e.which==32){
alert("spaces are not allowed");
}
});
});
</script>
<textarea></textarea>
【讨论】: