ASP.NET不允许输入空格

方法一:

<script type="text/javascript">
       
function isNull() {
           
if (window.event.keyCode==32) {
               
return false;
            }
        }
   
</script>

if(string.IsNullOrEmpty(TextBox1.text.Trim()))

{

}

方法三:

if (document.getElementById("txt_1").value.indexOf(' ') != -1) {
                alert(
'已包含空格符');
            }

    <asp:TextBox ID="TextBox1" runat="server" onkeydown="return isNull();"></asp:TextBox>
方法二:
原文地址:https://www.cnblogs.com/wuhuisheng/p/2016314.html