Home Backend Development PHP Tutorial php使用filter过滤器验证邮箱 ipv6地址 url验证_PHP

php使用filter过滤器验证邮箱 ipv6地址 url验证_PHP

Jun 01, 2016 am 11:58 AM
ipv6 url verification

IPv6

1、验证邮箱

复制代码 代码如下:
$email = 'jb51@qq.com';
$result = filter_var($email, FILTER_VALIDATE_EMAIL);
var_dump($result); //string(14) "jb51@qq.com"

2、验证url地址

复制代码 代码如下:
$url = "http://www.bitsCN.com";
$result = filter_var($url, FILTER_VALIDATE_URL);
var_dump($result); //string(22) "http://www.bitsCN.com"

3、验证ip地址

复制代码 代码如下:
$url = "192.168.1.110";
$result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); //string(13) "192.168.1.110"

值的一提的是,这方法也可以用来验证ipv6。

复制代码 代码如下:
$url = "2001:DB8:2de::e13";
$result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); //string(17) "2001:DB8:2de::e13"

4、验证数值是否为整数,并且在一个整数区间内

复制代码 代码如下:
$i = '010';
$result = filter_var(
    $i,
    FILTER_VALIDATE_INT,
    //设定校验的数值范围
    array(
      'options' => array('min_range' => 1, 'max_range' => 100)
    )
);
var_dump($result);//bool(false)

php的变量是弱类型,如果不用过滤器,直接使用大于小于符号判断的话会是真的。

复制代码 代码如下:
$i = '010';
$result = $i >= 1 && $i var_dump($result);//bool(true)

5、验证浮点数

复制代码 代码如下:
$float = 12.312;
$result = filter_var($float, FILTER_VALIDATE_FLOAT);
var_dump($result); //float(12.312)

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 admin@php.cn

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Disable IPv6 Windows 11: Why and how to change it Disable IPv6 Windows 11: Why and how to change it Apr 14, 2023 pm 01:07 PM

IPv6 stands for Internet Protocol version 6, the next generation of Internet addressing. It was developed to replace the current Internet Protocol (IPv4). IPv6 is an integral part of networking as it offers many benefits over its predecessors. Considering how long it took for IPv6 to be adopted, not every user has warmed up to IPv11. Even though Windows 6 has new features that make it ideal for the IPV protocol, some people still prefer to disable it. If you are one of them, we will show you how to do it. Should you disable IPv6 in Windows 11? In the internet world, such as gaming and streaming, IPv6 is necessary for the smooth functioning of a website or application. However, some

What are the benefits of turning on ipv6 on the router 'Advantages of using the latest IPv6' What are the benefits of turning on ipv6 on the router 'Advantages of using the latest IPv6' Feb 06, 2024 pm 05:34 PM

Students who know computers all know that if our computer wants to connect to the network, it must have an IP address. This IP address can be manually configured, such as 172.16.19.20; it can also be automatically obtained by the DHCP server of the computer network card, such as 192.168.1.100 etc. These IP addresses are what we often call IPV4 addresses, and the corresponding IPV6 is also a type of IP address. What is IPV6 IPV6 is a new IP address that emerged in response to the exhaustion of IPV4 address resources. Its full name is "Internet Protocol Version 6", and its Chinese name is the sixth generation of Internet Protocol. The number of IPv6 addresses is theoretically 2^128

Are ipv6 and wifi6 the same thing? Introduction to the difference between ipv6 and wifi6 Are ipv6 and wifi6 the same thing? Introduction to the difference between ipv6 and wifi6 Mar 14, 2024 pm 08:34 PM

IPv6, the full name of "Internet Protocol Version 6", is the next generation IP protocol designed by the Internet Engineering Task Force (IETF) to replace IPv4. Then some users asked, are ipv6 and wifi6 the same thing? Are these two the same? Of course they are different, let’s take a look at the detailed introduction below. The difference between ipv6 and wifi6: 1. First of all, ipv6 is an "IP protocol", while wifi6 is a "wifi standard". 2. IPv6 is an upgraded version of IPv4 and is used to solve the problem of insufficient network address resources. 3. In short

Analyze the detailed solution to the problem of normal IPv6 but no IPv4 network access permission in win11 system Analyze the detailed solution to the problem of normal IPv6 but no IPv4 network access permission in win11 system Jan 29, 2024 pm 06:33 PM

When we use win11 computers, we will encounter the problem of network connection failure. For example: ipv4 does not have network access permissions but ipv6 does. What is going on? Users can open the network and internet settings options interface to operate. Let this site carefully introduce to users the details of the analysis of the problem of normal ipv6 and ipv4 without network access rights in win11 system. Win11 system ipv6 normal ipv4 no network access problem analysis details 1. Right-click the network icon and open the network and internet settings. 3. Select Internet Protocol Version 4 and click Properties.

Disable IPv6 for CentOS 7, use only IPv4 Disable IPv6 for CentOS 7, use only IPv4 Jan 15, 2024 pm 10:39 PM

centos7 uses the ipv6 protocol. If a problem occurs, it will be difficult to troubleshoot. So if you want to turn off ipv6, how should you turn it off? Let’s take a look at the detailed tutorial below. 1. Use the ifconfig command to check the network card information. If inet6fe80::20c:29ff:fed0:3514 appears, it means that the machine has ipv62 enabled. Edit the /etc/sysctl.conf configuration and add net.ipv6.conf.all.disable_ipv6=13. Edit /etc/sysconfig/network configuration, add NETWORKING_IPV6=no, save and exit 4. Edit /etc/s

How to verify if a URL contains a specified string using regular expressions in PHP How to verify if a URL contains a specified string using regular expressions in PHP Jun 24, 2023 am 09:39 AM

With the development of the Internet, URLs have become an integral part of people's daily lives. Sometimes, we need to validate a URL to determine if it contains a specific string. In PHP, you can use regular expressions to perform this process. This article will introduce how to use regular expressions to verify whether a URL contains a specified string in PHP. First, we need to understand some basic concepts in regular expressions. Regular expressions are expressions used to match string patterns. It is a special syntax used in patterns

How to use regular expressions to verify URL addresses in golang How to use regular expressions to verify URL addresses in golang Jun 24, 2023 pm 04:00 PM

In recent years, with the rapid development of the Internet, our lives are increasingly inseparable from the Internet. When we use the Internet, we often need to enter or provide a URL address. In order to ensure security and accuracy, we need to verify the entered URL address. This article will introduce how to use regular expressions in golang to verify URL addresses. Basic components of a URL address A standard URL address contains the following parts: Protocol: such as http, https, ftp, etc. domain name

How to use regular expressions in golang to verify whether the URL address is a second-level domain name How to use regular expressions in golang to verify whether the URL address is a second-level domain name Jun 25, 2023 pm 06:30 PM

It is a common requirement in golang to use regular expressions to verify whether the URL address is a second-level domain name. In this article, we will introduce how to use regular expressions in golang for verification, and how to write regular expressions to verify whether a URL address is a second-level domain name. First, let's take a look at the basic usage of regular expressions in golang. Golang provides a regular expression library regexp. We can use regular expressions by calling the regexp package. Using regular tables

See all articles