So again, 'all letters' is a little hazy, because in different languages, different letters exist.
For the moment, I will assume you mean the Latin alphabet a-z, A-Z. I will also assume that the item you're checking is a single-line String.
You can extend this from there, if need be.
\w to be A-Z, a-z, 0-9, and the underscore (_). So we can use that. We want to add the hyphen, and period. Period is a gotcha character, because it has a special meaning. So we need to escape that character as
\. Hyphen can cause issues too, because it can be used to represent a range of things (As in A-Z). So we'll escape that one as well.
So we want there to be SOMETHING in the field. It needs to be a set of characters that match
\w\.\-. More specifically, we'd like to know if there's anything in the field that ISN'T those things. Regex defines a character set by putting square brackets around them. It defines "NOT this character set" by putting a carat (^) after the opening left-square-bracket. Our regex therefore is
We wrap regexes in a pattern delimiter, /.
If this function returns null, then the string complies with your rules. If it returns anything else, there was one or more illegal characters in it.