validation

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

Hello ,

I would like to check in c# if a given string consists only numbers or
letters,how can I validate it?

Thanks!
 
csharpula said:
I would like to check in c# if a given string consists only numbers or
letters,how can I validate it?

Use regular expressions e.g.
Regex.IsMatch(yourString, @"^[a-z0-9]+$", RegexOptions.IgnoreCase);

That assumes with "numbers" you want to test for the digits 0..9, with
"letters" for the letters a..z (case insensitive). Of course you can
change the pattern to your needs, the regular expression language in the
..NET framework is documented online here:
http://msdn.microsoft.com/en-us/library/hs600312.aspx
and of course in your local MSDN copy.
 
Back
Top