文本框的文本验证

文本框的文本验证

本文介绍了文本框的文本验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

在这里,我仅对字母和数字进行重排文本框

hi to all!

here i make to restrivt textbox for only alphabets and numbers

Regex regex = new Regex("^[a-zA-Z0-9]*$");



但我想在它们之间添加单个空格以及该怎么做
这样我就可以写这样的字符串



but i want to add single space between them as well how to do
so that i can write string like this

asd sdf
ah klh ksd ldf lk
lk djfg jbp


但不是这样的lkdjfg djgldfjg
我的意思是说他们之间只有一个空格


but not like this lkdjfg djgldfjg
i mean to say only single space between them

推荐答案



但我想在它们之间添加单个空格以及该怎么做
这样我就可以写这样的字符串



but i want to add single space between them as well how to do
so that i can write string like this

asd sdf
ah klh ksd ldf lk
lk djfg jbp


但不是这样的lkdjfg djgldfjg
我的意思是说它们之间只有一个空格


but not like this lkdjfg djgldfjg
i mean to say only single space between them


protected void btn_Click(object sender, EventArgs e)
        {
            string t = txt.Text.Trim();
            bool test = true;
            for (int i = 0; i < t.Length; i++)
            {
                if (t[i].ToString().Equals(" ") && t[i - 1].ToString() == " ")
                {
                    test = false;
                    break;
                }
            }
            if (test)
                Response.Write("Valid");
            else
                Response.Write("INValid");
        }


Regex regex = new Regex("^[a-zA-Z0-9 ]*


这篇关于文本框的文本验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:55