search
HomeBackend DevelopmentPHP TutorialCommonly used form validation classes_PHP tutorial
Commonly used form validation classes_PHP tutorialJul 20, 2016 am 11:00 AM
classfunctionpostforletterCommonly useddesignationnumberofkindcombinationformlengthverify

class class_post
{
//Verify whether it is a letter/number combination of the specified length
function fun_text1($num1,$num2,$str)
{
Return (preg_match("/^[a-zA-Z0-9]{".$num1.",".$num2."}$/",$str))?true:false;
}

//Verify whether it is a number of the specified length
function fun_text2($num1,$num2,$str)
{
return (preg_match("/^[0-9]{".$num1.",".$num2."}$/i",$str))?true:false;
}
//Verify whether it is a Chinese character of specified length
function fun_font($num1,$num2,$str)
{
// preg_match("/^[xa0-xff]{1,4}$/", $string);
return (preg_match("/^([x81-xfe][x40-xfe]){".$num1.",".$num2."}$/",$str))?true:false;
}
//Verify ID number
function fun_status($str)
{
return (preg_match('/(^([d]{15}|[d]{18}|[d]{17}x)$)/',$str))?true:false;
}

//Verify email address
function fun_email($str){
return (preg_match('/^[_.0-9a-z-] @([0-9a-z][0-9a-z-] .) [a-z]{2,4}$/',$str ))?true:false;
}
//Verify phone number
function fun_phone($str)
{
return (preg_match("/^(((d{3}))|(d{3}-))?((0d{2,3})|0d{2,3}-)?[1-9] d{6,7}$/",$str))?true:false;
}
//Verify zip code
function fun_zip($str)
{
return (preg_match("/^[1-9]d{5}$/",$str))?true:false;
}
//Verify url address
function fun_url($str)
{
return (preg_match("/^http://[A-Za-z0-9] .[A-Za-z0-9] [/=?%-&_~`@[]': !]*([^ ""])*$/",$str))?true:false;
}

//Enter data into the database and escape extraordinary characters. The incoming value can be a string or a one-dimensional array
function data_join(&$data)
{
if(get_magic_quotes_gpc() == false)
{
if (is_array($data))
{
foreach ($data as $k => $v)
{
$data[$k] = addslashes($v);
}
}
else
{
$data = addslashes($data);
}
}
Return $data;


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445547.htmlTechArticleclass class_post { //Verify whether it is a letter/number combination of the specified length function fun_text1($num1,$num2, $str) { Return (preg_match(/^[a-zA-Z0-9]{.$num1.,.$num2.}$/,$str))?true:false;...
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
Java实现表单的实时验证与提示功能Java实现表单的实时验证与提示功能Aug 07, 2023 am 10:42 AM

Java实现表单的实时验证与提示功能随着网络应用的普及和发展,表单的使用也变得越来越重要。表单是网页中用于收集和提交用户数据的元素,例如注册或登录页面的表单。在用户填写表单时,经常需要对其输入的数据进行验证和提示,以保证数据的正确性和完整性。在本文中,我们将介绍如何使用Java语言实现表单的实时验证与提示功能。HTML表单的搭建首先,我们需要使用HTML语言

如何在Nette框架中使用表单和验证?如何在Nette框架中使用表单和验证?Jun 04, 2023 pm 03:51 PM

Nette框架是一款用于PHPWeb开发的轻量级框架,以其简单易用、高效稳定的特点受到了广泛的欢迎和使用。在开发Web应用时,使用表单和验证是不可避免的需求。本文将介绍如何在Nette框架中使用表单和验证。一、表单构建在Nette框架中,表单可以通过Form类来创建。Form类在NetteForms命名空间中,可以通过use关键字引入。useNetteF

Spring注解大揭秘:常用注解解析Spring注解大揭秘:常用注解解析Dec 30, 2023 am 11:28 AM

Spring是一个开源框架,提供了许多注解来简化和增强Java开发。本文将详细解释常用的Spring注解,并提供具体的代码示例。@Autowired:自动装配@Autowired注解可以用于自动装配Spring容器中的Bean。当我们在需要依赖的地方使用@Autowired注解时,Spring将会在容器中查找匹配的Bean并自动注入。示例代码如下:@Auto

学习canvas框架 详解常用的canvas框架学习canvas框架 详解常用的canvas框架Jan 17, 2024 am 11:03 AM

探索Canvas框架:了解常用的Canvas框架有哪些,需要具体代码示例引言:Canvas是HTML5中提供的一个绘图API,通过它我们可以实现丰富的图形和动画效果。为了提高绘图的效率和便捷性,许多开发者开发了不同的Canvas框架。本文将介绍一些常用的Canvas框架,并提供具体代码示例,以帮助读者更深入地了解这些框架的使用方法。一、EaselJS框架Ea

如何在PHP表单中增加Token验证机制如何在PHP表单中增加Token验证机制Jun 24, 2023 pm 04:54 PM

在Web开发中,表单是用户和服务器之间沟通的重要渠道。为确保安全,我们需要在表单提交时添加Token验证机制来避免恶意攻击者的进攻。Token验证的基本原理是:服务器生成随机数,在表单中添加隐藏域的方式将Token传递给客户端,客户端提交表单时将Token发送回服务器,服务器验证Token的正确性,如果匹配,则允许表单提交,否则拒绝提交。下面我们将介绍在PH

15个常用的币圈逃顶指标技术分析15个常用的币圈逃顶指标技术分析Mar 03, 2025 pm 05:48 PM

十五大比特币逃顶指标深度解析:2025年市场展望本文深入分析了十五个常用的比特币逃顶指标,其中比特币Rhodl比率、USDT活期理财和山寨币季节指数已于2024年触及逃顶区间,引发市场关注。面对潜在风险,投资者该如何应对?让我们逐一解读这些指标,并探讨合理的应对策略。一、关键指标详解AHR999囤币指标:由ahr999创建,辅助比特币定投策略。当前值为1.21,处于观望区间,建议谨慎。链接AHR999逃顶指标:AHR999囤币指标的补充,用于识别市场顶部。当前值为2.48,本周

如何优化Vue开发中的表单自动填充问题如何优化Vue开发中的表单自动填充问题Jun 29, 2023 am 10:20 AM

如何优化Vue开发中的表单自动填充问题随着Vue框架的不断发展和应用,越来越多的开发者选择使用Vue来开发前端应用。在Vue开发过程中,表单是一个非常常见的组件,而表单自动填充问题也是开发者经常会遇到的一个问题。本文将介绍如何优化Vue开发中的表单自动填充问题,以提高用户体验。表单自动填充问题指的是当用户在表单中输入某些信息后,关闭浏览器再重新打开时,浏览器

Oracle数据库常用数据类型介绍Oracle数据库常用数据类型介绍Mar 08, 2024 am 09:45 AM

Oracle数据库是一种常用的关系型数据库管理系统,它支持多种数据类型以满足不同的需求。在使用Oracle数据库时,了解数据库的数据类型是非常重要的。本文将介绍Oracle数据库中常用的数据类型,并附带具体的代码示例。一、数值型数据类型NUMBERNUMBER是Oracle数据库中最常用的数值型数据类型,用于存储整数或浮点数。NUMBER数据类型可以指定精度

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

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 agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool