Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
want to check wether the string is alphanumeric or not
Posted
Updated 25-Aug-19 1:29am

Hello Vijay,
Try This
Alphanumeric is a combination of alphabetic and numeric characters.The alphanumeric character set consists of the numbers 0 to 9 and letters A to Z. for example these are the alphanumeric : Vijay1.
Dot Net Provides us the concept of Regular Expressions Under the Name Space System.Text . You Can Use Solution 1 as well.But i Intend to use RegularExpression. you can Modify Regular expression according to ur Criteria:
VB
Private Function IsAlphaNum(ByVal strInputText As String) As Boolean
      Dim IsAlpha As Boolean = False
      If System.Text.RegularExpressions.Regex.IsMatch(strInputText, "^[a-zA-Z0-9]+$") Then
          IsAlpha = True
      Else
          IsAlpha = False
      End If
      Return IsAlpha
  End Function

"^[a-zA-Z0-9]+$" is a Regular Expresiion.It Tells u a string can start from capital Characters,Small Characters Or Numbers and can contain combination of more then 1. Characters.
 
Share this answer
 
v2
Try this:
VB
Public Shared Function CheckIfAlphaNumeric(Str As String) As Boolean
 Dim IsAlpha As Boolean = True
 Dim c As Char

 Try
   For i As Integer = 0 To Str.Count - 1
   c = Str.Chars(i)
   If Not IsNumeric(c) And Not IsAlphabet(c) Then
     IsAlpha = False
   Exit For
   End If
 Next
 Catch ex As Exception
 IsAlpha = False
 End Try

Return IsAlpha
End Function


Refer more: How to check Alpha Numeric in a String[^]

Validate alphanumeric textbox[^]
 
Share this answer
 
i think this will help you
Convert the below code in VB.Net

C#
using System.Text.RegularExpressions;
....
....
....
private static bool CheckAlphaNumeric(string str)

{
return Regex.Match(str.Trim(), @"^[a-zA-Z0-9]*$").Success;

}


Also before asking please read MSDN or search it on search engines ...
 
Share this answer
 
v3
Solution 2 is just stupid. There is no "isAlphabet" in vb.net.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900