Vijay Kumbhoje
Vijay Kumbhoje

Reputation: 1441

Regex Forcing 3 minimum Characters in email address

I have regular expression ^[a-zA-Z0-9äöüÄÖÜß]{1}[äöüÄÖÜß\w\._%+-]{1}[äöüÄÖÜßa-zA-Z0-9]{1}@[\wäöüÄÖÜß]{1}[äöüÄÖÜß\w\.-]+\.[a-z]{2,4}$ for Email validation which accepts minimum 3 characters before @ sign, I want to allow one or more characters before @ sign. refer below explanation. [email protected] works fine but [email protected] doesn't work. I want user to enter atleast 1 character before @ sign.

Upvotes: 1

Views: 244

Answers (1)

The fourth bird
The fourth bird

Reputation: 163577

You can omit {1} from the pattern as the character class by itself without a quantifier matches 1 char. Currently you are matching exactly 3 characters, so you can just use a single character class and repeat that 1 or more times.

Note that you don't have to escape the dot in the character class.

^[a-zA-Z0-9][a-zA-Z0-9äöüÄÖÜß]*@[\wäöüÄÖÜß][äöüÄÖÜß\w.-]+\.[a-z]{2,4}$

See a regex demo

Upvotes: 4

Related Questions