could someone telle me please how to check if a string contains at least one alphabetical letter? I tryed:
if (StringName.Text.Contains(Char.IsLetter()))
{
//Do Something
}
But it doesn't work.
could someone telle me please how to check if a string contains at least one alphabetical letter? I tryed:
if (StringName.Text.Contains(Char.IsLetter()))
{
//Do Something
}
But it doesn't work.
You can use LINQ:
if (StringName.Text.Any(Char.IsLetter))
{
// Do something
}
Try Linq. If you accept any Unicode letter, say, Russian ъ
:
if (StringName.Text.Any(c => char.IsLetter(c)))
{
// Do Something
}
In case you want just a..z
as well as A..Z
:
if (StringName.Text.Any(c => c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'))
{
// Do Something
}
Finally, if you insist on regular expressions:
if (Regex.IsMatch(StringName.Text, @"\p{L}"))
{
// Do Something
}
Or (second option) a..z
as well as A..Z
letters only
if (Regex.IsMatch(StringName.Text, @"[a-zA-Z]"))
{
// Do Something
}