search
HomeBackend DevelopmentPHP Tutorial在PHP中的正则表达式印证

在PHP中的正则表达式验证<br>

验证是处处为站长的共同关注。如果有人进入形式的信息,您需要验证它!但是,这样做最简单的方法是什么?

嗯,处理大量的文本模式,需要遵循时,我总是转向正则表达式。正则表达式是你定义一个模式的一种方式。 虽然我不会教你的Regex,我会告诉正则表达式在PHP。PHP主要使用了Perl的regex的味道。这就是为什么要执行的功能在PHP正则表达式preg_match。执行Perl的正则表达式匹配,怎么做呢?无论如何,有某些修饰符,可以添加到PHP中的格局,影响它如何执行。 例如,“我”,使得它不区分大小写。我不得不这样做,电子邮件地址模式,因为它缩短假设您使用区分大小写的正则表达式模式的可读性。然后,有“米”修饰符将治疗一个多行的主题,实际上多个内衬。否则将被忽略,换行符(N)和锚点(^和$)将假定你的意思是整个主题的开头和结尾。“S”是有用的,如果你经常使用正则表达式的模式,不以^开始并没有一致的起始字符。 为了确定,如果该用户名,密码和验证密码是正确的,我以为只有字母数字字符是允许的。因此,寻找一切可能是一个潜在的错误的字符,而不是我是不是字母的字符搜索。这是由在字符类的字符^ [:^ A-ZA-Z0-9]。然后,后来,如果有一个比赛,我知道有一个在外地的无效字符。 同时请记住,有元字符,需要在正则表达式转义。我这个建议preg_quote 电子邮件和URL值是比较困难的,特别是因为这些标准是很难界定的。例如,在常规expressions.info,相当冗长的辩论已经到电子邮件的regex。从技术上来说,一个有效的电子邮件地址可以包含单引号。对于大多数的电子邮件地址,列出将是有效的。URL包含了类似的问题。众多的顶级域名,和一个列表是很难聚集。人也有一种倾向,只是说“software8.co”代替“http://software8.co”。也有情况下顶级域名中包含一个国家的价值,以及,像“google.co.uk”, 我不建议尝试,包括尽可能多的,你可以。如果您尝试,以满足大家,你最终验证上花费这么多时间,它已不再是可行的。验证用户输入,在你的代码是什么权宜之计,而不是根据是什么,他们将进入。 此外,regex是不是每一个问题的解决(虽然它是为大多数)。如果您要验证的东西,有许多例外或极其复杂,它成为一件苦差事。我什至不能想象试图日期和时间格式。中午12时或午夜吗?是12:60有效吗?约17:00怎么样?你需要上午和下午要输入吗?3意味着同为3:00?这些东西都是最好留给人类或其他一些方法,你可以制定。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php <br>
<br>
$un =$_POST["user"];<br>
$pw =$_POST["pass"];<br>
$pw2 =$_POST["pass2"];<br>
$em =$_POST["email"];<br>
$url =$_POST["url"];<br>
<br>
$info =array($un
Statement
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 admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment