Jump to content

Check a String for a character


$username

Recommended Posts

Hey Guys,

      I am a little lost at this.

I want to check to make sure the @ symbol is in the string.

 

Here is what I have

 

} else if($submit && empty($ContactEmail)  && strspn('@', $ContactEmail)) {

echo "<h4>You need to enter Email</h4> <br /> <a href=\"javascript:history.go(-1)\" onMouseOver=\"self.status=document.referrer;return true\">BACK</a> ";

 

 

This does nothing. It just goes to the next string. Is there a better way to check for a character

 

Thanks,

 

Link to comment
https://forums.phpfreaks.com/topic/182573-check-a-string-for-a-character/
Share on other sites

strstr

 

else if($submit && (empty($ContactEmail)  || strstr('@', $ContactEmail))) {
echo "<h4>You need to enter Email</h4> <br /> <a href=\"javascript:history.go(-1)\" onMouseOver=\"self.status=document.referrer;return true\">BACK</a> ";

 

You also had some logic issues, cause I take it you were seeing if the email was valid as well, doing the if $submit and contactemail is empty or contactemail does not contain an @ then error out :)

 

Hopefully that is what you were trying to get at.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.