VB.Net Validation: Checking if Text Contains Only Letters

regex, string, validation, vb.net

Solution

Use a Regular Expression

if System.Text.RegularExpressions.Regex.IsMatch(TextBox.Text, "^[A-Za-z]+$")) ...

Edit

The `^ $` character are anchors; they mean match the start and end-of-line respectively and can be used to prevent sub-string/partial matches.

E.g. The regex `X` would match `"X"` and `"AAAXAAA"` but `^X$` only matches `"X"` as its value can be thought of as `"<start of line>X<end of line>"`

Problem

Need to know how to validate a Text Box's text to make sure it contains ONLY letters without spaces. I was hoping some sort of functions exists which could help me, something like "IsString" or something.

Original source