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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Token Expiration Date. How? 11
Null and Generic Type 2
Regex with time 3
Validator Application Block 1
Validation 3
xml vs xsd 2
Excel VBA 0
Regex - Validate Url 4

Back
Top