Home > Software design >  Regex Forcing 3 minimum Characters in email address
Regex Forcing 3 minimum Characters in email address

Time:10-30

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.

CodePudding user response:

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

  • Related