PHP development form verification email and URL

怪我咯
Release: 2023-03-07 10:34:02
Original
1599 people have browsed it

PHP - Validation Name

The following code will use a simple way to detect whether the name field contains letters and spaces. If the name field value is illegal, error message will be output:

$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name))
  {
  $nameErr = "只允许字母及空格"; 
  }
Copy after login

PS:

preg_match — perform regular expression matching.

Syntax:

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

Search the subject string for the regular expression given by pattern content that matches the formula. If matches is provided, it will be populated with the results of the search. $matches[0] will contain text that matches the entire pattern, $matches[1] will contain text that matches the first captured subpattern in parentheses, and so on.

PHP - Verification Email

The following code will check whether the e-mail address is legitimate in a simple way. If the e-mail address is illegal, an error message will be output:

$email = test_input($_POST["email"]);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
  {
  $emailErr = "非法邮件地址"; 
  }
Copy after login

PHP - Validate URL

The following code will check whether the URL address is legal (the following regular expression runs in the URL containing dashes: "-"). If the URL address is illegal, an error message will be output:

$website = test_input($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website))
  {
  $websiteErr = "不合法的 URL"; 
  }
Copy after login

PHP - Validate Name, E-mail, and URL

The code is as follows:

Example

Copy after login

##

The above is the detailed content of PHP development form verification email and URL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!