Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all!

here i make to restrivt textbox for only alphabets and numbers

C#
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

but not like this lkdjfg djgldfjg
i mean to say only single space between them
Posted
Updated 26-Sep-11 19:52pm
v2

C#
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");
        }
 
Share this answer
 
Comments
kami124 27-Sep-11 3:17am    
thanks
Try this
C#
Regex regex = new Regex("^[a-zA-Z0-9 ]*$");
 
Share this answer
 
Comments
kami124 27-Sep-11 3:17am    
but in this way it took multiple space as well

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900