Loading ...

Regex to check for blank space

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Regex to check for blank space

Regex to check for blank space

Posts under the topic: Regex to check for blank space

Posted: 10/20/2010

Lurker 100  points  Lurker
  • Joined on: 9/11/2010
  • Posts: 20

Hi,

I have a textbox in my form I need a regex to check for blank space in that textbox value. How can I make it ?


Posted: 10/20/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490
  Answered

#region Using Directives

using System;
using System.Text.RegularExpressions;

#endregion

public class Example
{
    static void Main()
    {
        string input = "hello";
        string regex = @"^[\S]*$";
        bool isMatch = false;
        isMatch = Regex.IsMatch(input, regex);
        Console.WriteLine(isMatch ? "{0}: Matched" : "{0}: Not Matched", input);

        input = "hello good";
        isMatch = Regex.IsMatch(input, regex);
        Console.WriteLine(isMatch ? "{0}: Matched" : "{0}: Not Matched", input);

        Console.ReadLine();
        //Output:

        //hello: Matched
        //hello good: Not Matched
    }
}


tags regex, c#
Page 1 of 1 (2 items)