ExtensionMethod.NET Home of 820 C#, Visual Basic, F# and Javascript extension methods

ContainsNoSpaces

Checks if a string contains no spaces

Source

public static bool ContainsNoSpaces(this string s)
{
  var regex = new Regex(@"^[a-zA-Z0-9]+$");
  return regex.IsMatch(s);
}

Example

if (!textBoxUserIdNew.Text.Trim().ContainsNoSpaces())

Author: R. van Duren

Submitted on: 4 sep 2008

Language: C#

Type: System.String

Views: 2572