Opened 3 years ago
Closed 3 years ago
#2161 closed Enhancement (fixed)
Use filter_var() in is_email_address()
| Reported by: | paulb | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | Elgg 1.8.0 |
| Component: | Core | Version: | 1.7 |
| Severity: | trivial | Keywords: | |
| Cc: | brettp | Difficulty: | trivial |
Description
Please include a better email validation
file: engine/lib/users.php
line: 1363
Suggested solution:
// Added by Paul Bogdashkin
// paul.bogdashkin@gmail.com
function is_email_address($email)
{
// First, we check that there's one @ symbol, and that the lengths are right.
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[svn:0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
// Check if domain is IP. If not, it should be a valid domain name
if (!ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $email_array[svn:1])) {
$domain_array = explode(".", $email_array[svn:1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
}
Change History (3)
comment:1 Changed 3 years ago by cash
- Milestone changed from Elgg 1.7.2 to Elgg 1.8
comment:2 Changed 3 years ago by brettp
- Difficulty set to trivial
- Priority changed from normal to low
- Severity changed from minor to trivial
- Summary changed from email validation to Use filter_var() in is_email_address()
5.2 is a requirement by the new installer, so we can safely use filter_var().
comment:3 Changed 3 years ago by cash
- Resolution set to fixed
- Status changed from new to closed
(In [svn:7036]) Fixes #2161 - using filter_var() in email validation and moved is_email_address() to the input library
Note: See
TracTickets for help on using
tickets.

Would prefer to use filter_var(). Perhaps Elgg 1.8 should make PHP >= 5.2 a requirement?