Allan Shore
Allan Shore

Reputation:

howto write email pattern in mysql?

What I've tried is as below:

mysql> select '[email protected]' REGEXP '[a-zA-Z0-9_]+(?:[\-\+\.][a-zA-Z0-9_]+)*@[a-zA-Z0-9_]+(?:[\-\.\+][a-zA-Z0-9_]+)*\.[a-zA-Z0-9_]+(?:[\-\.\+][a-zA-Z0-9_]+)*';

ERROR 1139 (42000): Got error 'repetition-operator operand invalid' from regexp

And I've no idea what's wrong with it.

Can anyone here give me the right one that can work?

Thanks a lot!

Upvotes: 0

Views: 442

Answers (2)

Paweł Polewicz
Paweł Polewicz

Reputation: 3852

See here to learn about checking email with regexps. It appears it's a quite complex problem :-)

Upvotes: 0

t3rse
t3rse

Reputation: 10124

A simple regex that should match most email addresses:

[A-z0-9_.%+-]+@[A-z0-9_.%+-]+\.[A-z]{2,4}

Upvotes: 1

Related Questions