In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the PHP form must verify which fields, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.
PHP form-required fields
Field validation rules
Name is required. + can only contain letters and spaces
E-mail is required. + must contain a valid email address (including "@" and ".")
The web address is optional. If it exists, it must contain a valid URL
Remarks are optional. Multiline fields (text fields).
Gender is required. One must be selected.
:
PHP forms-validate messages and URL
Now let's learn how to verify names (name), e-mails (email), and URLs.
.
PHP-verify name
The following code detects whether the name field contains letters and spaces in a simple way, and outputs an error message if the name field value is illegal:
$name = test_input ($_ POST ["name"])
If (! preg_match ("/ ^ [a-zA-Z] * $/", $name)) {
$nameErr = "only letters and spaces are allowed"
}
.
Preg_match-regular expression matching is performed.
Http://www.iis7.com/a/lm/gjcpmcx/
Syntax: int preg_match (string $pattern, string $subject [, array $matches [, int $flags]])
Search the subject string for something that matches the regular expression given by pattern. If matches is provided, it is populated with the search results. $matches [0] will contain text that matches the entire pattern, $matches [1] will contain text that matches the subpattern in parentheses that was captured first, and so on.
.
PHP-validate messages
The following code will detect whether the e-mail address is valid in a simple way. If the e-mail address is invalid, an error message will be output:
$email = test_input ($_ POST ["email"])
If (! preg_match ("/ ([\ w\ -] +\ @ [\ w\ -] +\. [\ w\ -] +) /", $email)) {
$emailErr = "illegal mailbox format"
}
.
PHP-verify URL
The following code detects whether the URL address is valid (the following regular expression runs URL with a dash: "-"), and 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 thanks thanks #\ /%? = ~ _ |!:,.;] * [- a-z0-9 thanks / /% = ~ _ | / I", $website)) {
$websiteErr = "illegal URL address"
}
Thank you for reading this article carefully. I hope the article "which fields must be verified in the form in PHP" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.