How to check if a string contains strictly Letters and/or Numbers (ASP.NET)

Hello all,

This should be a simple question.  I would like to do a boolean test to ensure that a string contains letters or numbers or both.  Incase that is not clear, it may not contain any other character other than a letter or number.  Is there such a function in ASP.NET?


Please advise,

-TH
travishabermanAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
If Not Regex.IsMatch( String, "[^A-Za-z0-9]" ) Then
   
End If
0
 
Fahad MukhtarDistinguished EngineerCommented:
VB.Net or c#?
0
 
travishabermanAuthor Commented:
You know something.. I know this sounds stupid - But I don't even know.. I am fairly decent with C++ and this is my first time ever writing anything in a language like this..  I am working in the ASP "WEB MATRIX" .. Does that help?
0
 
travishabermanAuthor Commented:
Thank you much...!
0
 
Fahad MukhtarDistinguished EngineerCommented:
its C# at the moment: you can convert it to vb.net

foreach (Char c in s.ToCharArray() )
      {
      if (!Char.IsLetter(c))
           break; // non letter charactar
      }
            
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.