Form verification email and URL for PHP development

Source: Internet
Author: User
PHP-verification name the following code checks whether the name field contains letters and spaces in a simple way. if the name field value is invalid, an error message is output: $ nametest_input ($ _ POST [ PHP-verification name

The following code checks whether the name field contains letters and spaces. if the name field value is invalid, an error message is output:

$ Name = test_input ($ _ POST ["name"]); if (! Preg_match ("/^ [a-zA-Z] * $/", $ name) {$ nameErr = "only letters and spaces are allowed ";}

PS:

Preg_match-regular expression matching.

Syntax:

Int preg_match (string $ pattern, string $ subject [, array $ matches [, int $ flags])

Search for the content that matches the regular expression given by pattern in the subject string. If matches is provided, it is filled with the search results. $ Matches [0] will contain the text that matches the entire pattern, $ matches [1] will contain the text that matches the child pattern in the first captured bracket, and so on. PHP-verification email

The following code checks whether the email address is valid in a simple way. If the email address is invalid, the following error message is output:

$ Email = test_input ($ _ POST ["email"]); if (! Preg_match ("/([\ w \-] + \ @ [\ w \-] + \. [\ w \-] +)/", $ email) {$ emailErr =" invalid email address ";}
PHP-verify URL

The following code checks whether the URL address is legal (the following regular expression runs a URL containing a broken number: "-"). If the URL address is invalid, an error message is output:

$ Website = test_input ($ _ POST ["website"]); if (! Preg_match ("/\ B (? :(? : Https? | Ftp): \ // | www \.) [-a-z0-9 + @ # \/%? = ~ _ |! :,.;] * [-A-z0-9 + @ # \/% = ~ _ |]/I ", $ website) {$ websiteErr =" invalid URL ";}
PHP-verify Name, email, and URL

The code is as follows:

Instance

 

The above is the details of form verification emails and URLs developed by PHP. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.