swaminadhan
Joined: 14 Sep 2009 Posts: 51
|
Posted: Wed Dec 30, 2009 1:11 pm Post subject: Email validation in mysql: |
|
|
hello developers !
How to validate e-mail address in MySQL ?
Most people validate e-mail addresses in a normal programming language, such as PHP,Ruby On Rails ,...and that is a very good idea when you process user input , however sometimes you want to validate data already entered in a database.
for example:
you have a user table where each person can enter an e-mail address, but since it’s an optional field you don’t even validate the input. However when you need to send a newsletter you don’t want to process all fields and validate one by one, you want to use a single query and just get all e-mail addresses (eventually by adding additional rules as well), so here’s how you can do it in MySQL:
SELECT * FROM users WHERE email NOT 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]\.[a-zA-Z]{2,4}$'
even we can optimize the query based on our requirement.
Thank you,
swaminadhan. |
|