I need to validate an input to be either empty or only contain letters. The letter part I got figured out at ^[a-zA-Z]+$ . How can I accept the input if it's empty too?
Try changing your + to a *, as in this pattern:
^[a-zA-Z]*$
This will match zero or more Latin letters, so it will accept an empty string as well.
For international support, you might also want to consider:
^\p{L}*$
This will match zero or more letters in any Unicode language.
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