FILTER_VALIDATE_EMAIL not validating [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Here's the code I'm using:
if (filter_var($desired_username, FILTER_VALIDATE_EMAIL) || ((strlen($desired_username)) > 32)) {
$usernamevalidate=FALSE;
} else {
$usernamevalidate=TRUE;
}
strlen is working perfectly, but either filter_var or FILTER_VALIDATE_EMAIL is not. Don't let the variable name trick you, "$desired_username" links to a field for an email, but it's just not working.
I can enter "test" instead of "test#test.com" or even "test#test" and it still validates. I've also tried preg_match and other methods, but none of them are validating properly.
Any help would be appreciated.

Several things:
You seem to be mixing up username and e-mail. Many e-mails are longer than 32 characters.
You've got how filter_var works backwards. A valid e-mail is going to set $usernamevalidate=FALSE with your code.
You should be doing this instead:
if(filter_var($desired_username, FILTER_VALIDATE_EMAIL)) {
$usernamevalidate=TRUE;
} else {
$usernamevalidate=FALSE;
}

Related

working with nested if query [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hi I have a field which is supposed to display 1 of 3 icons based on a 2 conditions.
The key field here is VisitPlanRequired, if the answer to this is a "No" then the the icon should be na.png, however if it a "Yes", it then depends on another variable.
So if VisitPlanRequired = yes, then the two options are either ok.jpg or notok.jpg, the actual decider is whether the field VisitPlanIssued is null or contains a date, so if it contains a date, it should go to "ok", if it doesnt, it should go to notok.
This is the code I have so far, but I am struggling to get it to work for all three conditions, I would appreciate your help:
if ($data["VisitPlanRequired"]==='No')
$value="<img src=images/na.png id='image'>";
elseif
($data["AuditPlanIssued"])
{ $value="<img src=images/ok.jpg id='image'>";}
else
$value="<img src=images/notok.jpg id='image'>";
Something like this (really the basics of programming actually...
if ($data["VisitPlanRequired"] == 'No'){
$value="<img src=images/na.png id='image'>";
}else{
if( !empty($data["AuditPlanIssued"]) ){
$value="<img src=images/ok.jpg id='image'>";
}else{
$value="<img src=images/notok.jpg id='image'>";
}
}
Success

How to access $_Get variable in PHP based on another input value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I need to access the input value of a dynamic variable based on another input field.
Sample code:
$upid=$_GET['upid'];
$check_box_name='c'.$upid;
echo $upid;
$check=$_GET[$check_box_name];
any idea how do i access it??...Please help
The code you entered should work, but, it is vulnerable to errors, as you are dealing with a user input, you should either do a validation or a failover value.
If you are using PHP5.3+, you can easily do this as follows:
if ($check = #$_GET['c' . (#$_GET['upid'])]? : false !== false) {
//do something with $check
} else {
//failed
}
The # sign is used to omit any error or exception from being thrown. Also, it maybe a good thing to escape the $check variable for more security.

why is my email validation not working [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I would appreciate some help validating an email address in PHP. The format for the email that I need is firstname.lastname#mohawkcollege.TLD, .com, .ca, or .org being valid TLDs.
My function is:
function validateEmail($email)
{
$regex = "/[a-zA-Z0-9_-.+]+#[a-zA-Z0-9-]+.[a-zA-Z]+/";
if (!preg_match($regex, $email))
{
return "<li>Email is in wrong format</li>"
}
}
Use:
/[a-zA-Z0-9-_.+]+#[a-zA-Z0-9-]+.[a-zA-Z]+/
or
/[a-zA-Z0-9_\-.+]+#[a-zA-Z0-9-]+.[a-zA-Z]+/
Put - after _ would make a confusion, so either escape it or put it before _

PHP IF AND statement won't execute else section [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am trying to use an IF AND statement in PHP to test for
The submit button being pressed and
That my $testemail varable is equal to one, ie valid email in a PHP script.
If the Email is good , I get:
Thank you, 1 // ( this is correct) and email is sent
If the email is bad I get:
Thank you, 0. // ( this is not correct ) and email is still trying to be sent with bad email address.
Because the script is outputting the 0 or 1 properly, I am certain it has tested the email and correctly deciding if it is good or bad ( hence the '0' and the '1') but the script never goes to the else statement. I can't seem to get the IF AND statement right. I have tried "1" and '1'.
Very confused. Thanks in advance.
if(!filter_var($emailtmp, FILTER_VALIDATE_EMAIL))
{
$testemail = "0";
}
else
{
$testemail = "1";
}
global $testemail;
var_dump($testemail);
if (isset($_POST['submit']) && ($testemail = 1) )
{
//Everything is good, proceed
sendEmail(preg_replace(array('/<td>.*href="\?remove.*<\/td>/i', '/<th.*
<\/th>/i'), '', $_SESSION['SHOPPING_CART_HTML']));
$result_message = "Thank You. $testemail ";
}
elseif (isset($_POST['submit']))
{
//Missing Required Information
$result_message = "You must use a Valid email addresse, $testemail ";
}
($testemail = 1)
should be
($testemail === 1)
Having just ($testemail = 1) simply sets the value of testemail to 1 (which for the purposes of the if, is true since its successful). == or better yet the more exact === is what you want for checking if the left & right values match.
The problem is you are assigning the value 1 to $testemail instead of comparing it.

How to check a string contain alphabet or not [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a simple php program which is getting the data from the url, but I want to check whether it contains a alphabet or not.
The data which I get from the url is as follows ?query=seller,12. I used ctype_alpha() for this, but I am getting no result for this. I have a rough idea that it can be done by preg_match() but I don't how to do it.
Please help me as I am beginner to php.
Thanks in advance
Here you go,
<?php
$subject = "?query=seller,12";
if(preg_match('/[a-zA-Z]/', $subject)){
echo "It has a alphabet";
}
?>
if you want to print all the characters from that string, you can use like this
preg_match_all('/[a-zA-Z]/', $subject,$matches);
print_r($matches);
$matches is an array of all available matches of the specified pattern
Try this dude.
if (!preg_match('/[^A-Za-z]/', $string)) // '/[^a-z\d]/i' should also work.
{
// string contains only english letters
}

Categories