I'm trying to create a regex that will match only when the string has anything but alphas, spaces, and hyphens. In other words, the string can only contain letters, spaces, and hyphens.
If you are looking for a test for validity:
// from string start to end, only contains '-' "whitespace" or 'a'-'z'
someString.match(/^[-\sa-zA-Z]+$/)
Or the negation:
// has some invalid character not '-' "whitespace" or 'a'-'z'
someString.match(/[^-\sa-zA-Z]/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With