如何避免第一个字符作为TextBox中的空格 [英] How to avoid first character as a space in TextBox

查看:127
本文介绍了如何避免第一个字符作为TextBox中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,如果有人输入'space'作为第一个字符,我想停止收益。

如果第一个字符是空格,是否可以将值赋给变量v_MyAddressStreet作为(空白)。

我不想使用'必填字段验证'



In the following code I want to stop the proceeds if someone enters 'space' as a first character.
If the first character is a space, is it possible to assign the value to variable v_MyAddressStreet as "" (blank).
I dont want to use 'Required field validation'

protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {

       v_MyAddressStreet = TextBox10.Text;
       if (v_MyAddressStreet == "")
       {
           RBL7clear();
       }
   }

推荐答案

如果您的意思是我想知道字符串是空白还是空白,然后是theW IsNullOrWhiteSpace方法:

If you mean "I want to know if the string is blank or empty, then there is thew IsNullOrWhiteSpace method:
protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {
       v_MyAddressStreet = TextBox10.Text;
       if (string.IsNullOrWhiteSpace(v_MyAddressStreet))
       {
           RBL7clear();
       }
   }

如果该字段为空,则为空,或只是包含空格,将调用RBL7clear方法。

If the field is null, empty, or just contains spaces the RBL7clear method will be called.


我想如果你只检查 v_MyAddressStreet.StartsWith(),这将为你做伎俩。它会检查第一个字符我空间与否。也请关注这个:

如何阻止文本框中的第一个字符成为空格? [ ^ ]
I think if you just check v_MyAddressStreet.StartsWith(" "), that will do the trick for you here.It will check if the first character is space or not. Follow this one also:
How to stop the first character in a text box from being space?[^]


protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {
if(TextBox10.Text!="")
{


       
           RBL7clear();
      
}
else 
{
//show your message
}
   }


这篇关于如何避免第一个字符作为TextBox中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆