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!