How to check if a string contains alphabets?

code
studio

#1

I can check if a string contains an integer but unable to do for a alphabet?


#2

Hey @ishankakar

Regex.Matches(yourstring,"[a-zA-Z]").Count

Remember to use Regex class, you have to use namespace System.Text.RegularExpressions in your import

or one more way

bool result = hello.Any(function(x) NOT char.IsLetter(x))

For above you have to import System.LINQ namespaces in your project.

Regards…!!
AKsh


#3

@aksh1yadav
Thank you for your help


#4

@aksh1yadav
For alphabets it’s working fine but I want to check for numbers as well


#5

Hey @Bachali

If you want to just check a string is only alphabets and Numbers then you can use below Regex Patter,

Int Count = Regex.Matches(str,"^[a-zA-Z0-9]+$").Count

By Linq -

Bool IsAlphnumornot="Your String".All(function(c) Char.IsLetterOrDigit(c))

or if you want to check that any character is Alphanumeric or Digits/Number as well then can use below Linq

Bool IsAlphnumornot=“Your String”.Any(function© Char.IsLetterOrDigit©)

Regards…!!
Aksh


#6

Thanks @aksh1yadav It’s working :blush: