A regular expression for at least one alphabet should not allow periods (.)

I wrote the following expression, but I had a problem:

^[^\.]*[a-zA-Z]+$

According to the above expression df45543is invalid, but I want to allow such a string. Only one character of the alphabet is required, and a period is not allowed. All other characters are allowed.

+4
source share
4 answers

You need to use lookahead to force a single alphabet:

^(?=.*?[a-zA-Z])[^.]+$

(?=.*?[a-zA-Z]) - This is a positive look that guarantees that at least one alphabet will be at the entrance.

+1
source

Just add numbers as valid characters:

^[^\.]*[a-zA-Z0-9]+$

Watch the demo

1 , lookaheads:

^(?!.*\.)(?=.*[a-zA-Z]).+$

(?!.*\.) , (?=.*[a-zA-Z]) .

- .

^(?!\.)(?=.*[a-zA-Z]).+$
+5

:

^[^.a-z]*[a-z][^.]*$

( , , A-Z )

0

, ^[^.]* ,

^[^.]*[A-Za-z]+[^.]*$

0

All Articles