Simple Email Validation
This might seem really noobish, but I wanted to create a simple, but effective email validation function.
Most other functions/classes were too complicated: they did things which I did not need and were way above me. My aim was to make sure that the email a user entered basically was an email.
I would love suggestions on how I could improve it, as I am sure there are improvements to be made!
I think we had a discussion similar to this before, and the conclusion was that we as programmers should not be using any advanced regex to check the syntax of an email address. After all, email validation would weed out any invalid emails, and then a crontab would come along and clear out any inactive accounts.
However, we should definitely by using a simple regex for checking the very simple structure of any given email address. Such as like:
Furthermore, being as sure as possible that an email address is valid would be somewhat slow, and that is surely not a favourable sacrifice. After all, email address structures can be very complicated.
A good first thing to do would be to switch from using
For the regular expression itself, you've made an ok start. However, this falls victim of a hugely common bug in many "validation" checks: it would flag
Since you're only checking to see if the pattern matches or not, there's no need to use capturing groups
Thanks for the input guys! You rock :P
I'm going to look up on preg_match, I don't use it that often so I'll need to remind myself of the syntax and uses etc.
But for now I've updated the function with returning the bools straight off.
|All times are GMT. The time now is 07:32 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0