InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

Menu
  • Home
  • Sitemap

Python Programming Language Best Tutorials and Code Examples

Learn Python Right Now!
Home
PHP
Validating Form Input: Email Addresses in PHP
PHP

Validating Form Input: Email Addresses in PHP

InfinityCoder November 28, 2016

You want to know whether an email address a user has provided is valid.

Use the FILTER_VALIDATE_EMAIL filter, as show in Example 9-9. It tells you whether an email address is valid according to the rules in RFC 5321 (mostly).
Example 9-9. Validating an email address

1
2
3
4
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($email === false) {
   print "Submitted email address is invalid.";
}

RFC 5321 consolidates a number of email-related RFCs and defines the standards for a valid email address.

The FILTER_VALIDATE_EMAIL filter uses a regular expression based on those rules, although it explicitly does not support comments or folding whitespace.
The filter only checks that a particular address is syntactically correct. This is useful for preventing a user from accidentally telling you that her email address is bingolover2261@example instead of bingolover2261@example.com.

What it doesn’t tell you, however, is what happens if you send a message to that address. Furthermore, it doesn’t
let you know that the person providing the email address is in control of the address.
For those sorts of validations, you need to send a confirmation message to the address.

The confirmation message can ask the user to take some affirmative task (reply to the message, click on a link) to indicate they’re the same person that entered the address on the form.

Or, the confirmation message can tell the user what to do if she’s not the same person that entered the address on the form — such as to click on a link in the messsage to indicate the wrong address was entered.

Recipe 8.19 demonstrates a system that sends an email message containing a link that the recipient must click on to confirm that she provided the address.

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Getting Information About a Domain Name in PHP
You want to look up contact information or other details …

Getting Information About a Domain Name in PHP

Program: Finding Fresh Links in PHP
Example 13-23 is a modification of the program in Example …

Program: Finding Fresh Links in PHP

About The Author

InfinityCoder
InfinityCoder

Leave a Reply

Cancel reply

Recent Tutorials InfinityQuest

  • Adding New Features to bash Using Loadable Built-ins in bash
    Adding New Features to bash Using Loadable …
    June 27, 2017 0
  • Getting to the Bottom of Things in bash
    Getting to the Bottom of Things in …
    June 27, 2017 0

Recent Comments

  • fer on Turning a Dictionary into XML in Python
  • mahesh on Turning a Dictionary into XML in Python

Categories

  • Bash
  • PHP
  • Python
  • Uncategorized

InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

About Us

Start learning your desired programming language with InfinityQuest.com.

On our website you can access any tutorial that you want with video and code examples.

We are very happy and honored that InfinityQuest.com has been listed as a recommended learning website for students.

Popular Tags

binary data python CIDR convert string into datetime python create xml from dict python dictionary into xml python how to create xml with dict in Python how to write binary data in Python IP Address read binary data python tutorial string as date object python string to datetime python

Archives

  • June 2017
  • April 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
Copyright © 2021 InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more
Programming Tutorials | Sitemap