I have written the regex below but I'm facing an issue:
^[^\.]*[a-zA-Z]+$
As per the above regex, df45543
is invalid, but I want to allow such a string. Only one alphabet character is mandatory and a dot is not allowed. All other characters are allowed.
Just add the digits as allowed characters:
^[^\.]*[a-zA-Z0-9]+$
See demo
In case you need to disallow dots, and allow at least 1 English letter, then use lookaheads:
^(?!.*\.)(?=.*[a-zA-Z]).+$
(?!.*\.)
disallows a dot in the string, and (?=.*[a-zA-Z])
requires at least one English letter.
See another demo
Another scenario is when the dot is not allowed only at the beginning. Then, use
^(?!\.)(?=.*[a-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