I am trying to do an SQL query, but I need to check somehow if the value is an email address. I need a way to check if $user
is an email address, because I have user values such as this in my table.
test test2 [email protected] [email protected] test392 [email protected]
and so on...
I need to make it so $useremail
checks $user
to find if it's an email address. So I can UPDATE the values, WHERE user=test OR [email protected]
, etc.
$user = strtolower($olduser); $useremail = ""; mysql_query("UPDATE _$setprofile SET user=$sn, fc=$fc WHERE user='$user' OR user='$useremail");
To verify that the email address is valid, the IsValidEmail method calls the Regex. Replace(String, String, MatchEvaluator) method with the (@)(. +)$ regular expression pattern to separate the domain name from the email address.
Explanation: In the above example, passing the input email address to the predefined function filter_var(), which takes two parameters as input email and second is type of email filter. This function filters the email and returns true or false. Method 3: Email validation using FILTER_SANITIZE_EMAIL filter.
Without regular expressions:
<?php if(filter_var("[email protected]", FILTER_VALIDATE_EMAIL)) { // valid address } else { // invalid address } ?>
This is not a great method and doesn't check if the email exists but it checks if it looks like an email with the @ and domain extension.
function checkEmail($email) { $find1 = strpos($email, '@'); $find2 = strpos($email, '.'); return ($find1 !== false && $find2 !== false && $find2 > $find1); } $email = '[email protected]'; if ( checkEmail($email) ) { echo $email . ' looks like a valid email address.'; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With