问题描述
我需要验证文本框,而不能在起始位置留空格,并且两个单词之间只能留一个空格..
1234567
例如:Vino Pr --->正确:第5个位置是空格,即只允许一个位置.
123456789
例如:Vino Pr --->此示例在第1位置允许的空间不正确,并且在
之间允许2个空格..我需要在文本框中获取输入,不允许在第1个位置使用空格,并且在单词之间不允许使用多个空格.
我使用了Text.StartTrim().EndTrim()
从文本框添加到gridview时它正确显示.
但是从Gridview到数据库,它允许有空格.
Hi huys i need to validate the textbox without allowing space starting position and allowing only one space between two words..
1234567
Ex:Vino Pr--->correct: 5th position is space i.e only one position is allowed.
123456789
Ex: Vino Pr--->This Example is incorrect 1st Position allowed Space and in between
allowed 2 spaces.. i need to textbox to get input not allowing the space in the 1st position and not allow the more than one space between the words.
i used the the Text.StartTrim().EndTrim()
it coming correctly while adding in the gridview from textbox.
But from Gridview to database it allowing the spaces.
推荐答案
<script type="text/javascript">
function AllowSingleSpaceNotInFirstAndLast() {
var obj = document.getElementById('TextBox1');
obj.value = obj.value.replace(/^\s+|\s+
Username: <input type="text" id="TextBox1" name="user" />
<input type="button" value="Submit" onclick="return AllowSingleSpaceNotInFirstAndLast();" />
如果它回答了您的问题,请将其标记为解决方案
Mark it as solution if it answer your question
<div>
<script type=""text/javascript">
language="javascript">
function isNumberKey(evt) {
// if (!(((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) || (event.keyCode == 8) || (event.keyCode == 9) || (event.keyCode == 37) || (event.keyCode == 39) || (event.keyCode == 46) || (event.keyCode == 190) || (event.keyCode == 35) || (event.keyCode == 36)))
//event.returnValue=false;
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && charCode < 48 || charCode > 57)
if (event.keyCode != 46)
if (event.keyCode != 110)
return false;
return true;
}
</script>
close the script tag
<asp:textbox id="txtAdm" runat="server" onkeypress="return isNumberKey(event)" xmlns:asp="#unknown">
Width="150px" MaxLength="8"></asp:textbox>
</div>
这篇关于不允许空格的Java脚本验证.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!