检查字符串长度 检查字符串是否为空 用正则表达式验证出版物的ISBN号 用正则表达式验证邮证编码 验证字符串中是否含有汉字
- <?php
- /**
- * 常用的正则表达式来验证信息.如:网址 邮箱 手机号等
- */
- class check {
- /**
- * 正则表达式验证email格式
- *
- * @param string $str 所要验证的邮箱地址
- * @return boolean
- */
- public static function isEmail($str) {
- if (!$str) {
- return false;
- }
- return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $str) ? true : false;
- }
- /**
- * 正则表达式验证网址
- *
- * @param string $str 所要验证的网址
- * @return boolean
- */
- public static function isUrl($str) {
- if (!$str) {
- return false;
- }
- return preg_match('#(http|https|ftp|ftps)://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?#i', $str) ? true : false;
- }
- /**
- * 验证字符串中是否含有汉字
- *
- * @param integer $string 所要验证的字符串。注:字符串编码仅支持UTF-8
- * @return boolean
- */
- public static function isChineseCharacter($string) {
- if (!$string) {
- return false;
- }
- return preg_match('~[\x{4e00}-\x{9fa5}]+~u', $string) ? true : false;
- }
- /**
- * 验证字符串中是否含有非法字符
- *
- * @param string $string 待验证的字符串
- * @return boolean
- */
- public static function isInvalidStr($string) {
- if (!$string) {
- return false;
- }
- return preg_match('#[!#$%^&*(){}~`"\';:?+=<>/\[\]]+#', $string) ? true : false;
- }
- /**
- * 用正则表达式验证邮证编码
- *
- * @param integer $num 所要验证的邮政编码
- * @return boolean
- */
- public static function isPostNum($num) {
- if (!$num) {
- return false;
- }
- return preg_match('#^[1-9][0-9]{5}$#', $num) ? true : false;
- }
- /**
- * 正则表达式验证身份证号码
- *
- * @param integer $num 所要验证的身份证号码
- * @return boolean
- */
- public static function isPersonalCard($num) {
- if (!$num) {
- return false;
- }
- return preg_match('#^[\d]{15}$|^[\d]{18}$#', $num) ? true : false;
- }
- /**
- * 正则表达式验证IP地址, 注:仅限IPv4
- *
- * @param string $str 所要验证的IP地址
- * @return boolean
- */
- public static function isIp($str) {
- if (!$str) {
- return false;
- }
- if (!preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $str)) {
- return false;
- }
- $ipArray = explode('.', $str);
- //真实的ip地址每个数字不能大于255(0-255)
- return ($ipArray[0]<=255 && $ipArray[1]<=255 && $ipArray[2]<=255 && $ipArray[3]<=255) ? true : false;
- }
- /**
- * 用正则表达式验证出版物的ISBN号
- *
- * @param integer $str 所要验证的ISBN号,通常是由13位数字构成
- * @return boolean
- */
- public static function isBookIsbn($str) {
- if (!$str) {
- return false;
- }
- return preg_match('#^978[\d]{10}$|^978-[\d]{10}$#', $str) ? true : false;
- }
- /**
- * 用正则表达式验证手机号码(中国大陆区)
- * @param integer $num 所要验证的手机号
- * @return boolean
- */
- public static function isMobile($num) {
- if (!$num) {
- return false;
- }
- return preg_match('#^13[\d]{9}$|14^[0-9]\d{8}|^15[0-9]\d{8}$|^18[0-9]\d{8}$#', $num) ? true : false;
- }
- /**
- * 检查字符串是否为空
- *
- * @access public
- * @param string $string 字符串内容
- * @return boolean
- */
- public static function isMust($string = null) {
- //参数分析
- if (is_null($string)) {
- return false;
- }
- return empty($string) ? false : true;
- }
- /**
- * 检查字符串长度
- *
- * @access public
- * @param string $string 字符串内容
- * @param integer $min 最小的字符串数
- * @param integer $max 最大的字符串数
- */
- public static function isLength($string = null, $min = 0, $max = 255) {
- //参数分析
- if (is_null($string)) {
- return false;
- }
- //获取字符串长度
- $length = strlen(trim($string));
- return (($length >= (int)$min) && ($length <= (int)$max)) ? true : false;
- }
- }
检查字符串长度 检查字符串是否为空 用正则表达式验证出版物的ISBN号 用正则表达式验证邮证编码 验证字符串中是否含有汉字的更多相关文章
- c c++怎么判断一个字符串中是否含有汉字
c c++怎么判断一个字符串中是否含有汉字 (2013-02-05 10:44:23) 转载▼ #include #include int main() { char sztext[] = ...
- java判断字符串中是否含有汉字
原文:http://www.open-open.com/code/view/1426332240717 判断字符串中是否含有汉字: String str = "test中文汉字"; ...
- c# 判断字符串中是否含有汉字,数字
正则表达式使用时需要引用 using System.Text.RegularExpressions; private void buttonX1_Click(object sender, EventA ...
- php_match/preg_match_all 默认有字符串长度限制
php_match/preg_match_all 默认有字符串长度限制:52500(或许你的服务器环境是更长,或者更短),当字符串长度大于52500,只能匹配到52500数据,超出的部分会被系统自己截 ...
- PHP获取中英文混合字符串长度及截取
1.字符串长度 PHP获取中英文混合字符串长度的实现代码如下,1中文=1位,2英文=1位,可自行修改 /** * PHP获取字符串中英文混合长度 * @param $str string 字符串 * ...
- Shell脚本中字符串判空:使用-z 字符串长度为0时,为真,-n字符串长度不为0,为真。这两个都不靠谱【转】
最近发现使用 -z 和 -n 来判断字符串判空,或不空时,很不靠谱. 使用下面的方法最可靠: if [ "x${value}" == "x" ] ...
- php中常用的字符串长度函数strlen()与mb_strlen()实例解释
int strlen ( string $string ) int strlen ( string $string ) 获取给定字符串的[字节]长度 成功则返回字符串$string的长度,如果$s ...
- ★★★【卡法 常用js库】: js汇合 表单验证 cookie设置 日期格式 电话手机号码 email 整数 小数 金额 检查参数长度
[卡法 常用js库]: js汇合 表单验证 cookie设置 日期格式 电话手机号码 email 整数 小数 金额 检查参数长度 // +---------------------- ...
- php 字符串长度函数
php 字符串长度函数 php 字符串长度函数,在php测试字符串长度的函数有二个,一个是strlen,另一个是mb_strlen前一个默认是支持,后一个需要开启一个插件,下面我们来介绍一下二个函数的 ...
随机推荐
- OAF_架构MVC系列1 - MVC的概述(概念)
2015-04-03 Created By BaoXinjian
- HDU 5428 The Factor
话说这题意真的是好难懂啊,尽管搜到了中文题意,然而还是没懂,最后看到了一个题解才懂的.http://www.cnblogs.com/Apro/p/4784808.html#3470972 题意:给出n ...
- 转--Invalidate和postInvalidate的更新view区别
Android中实现view的更新有两组方法,一组是invalidate,另一组是postInvalidate,其中前者是在UI线程自身中使用,而后者在非UI线程中使用. Android提供了Inva ...
- JAVA 数组算法(复制、查找、插入)
一.复制数组算法 //数组复制算法 public class Test{ public static void main(String[] args){ int[] arrA = {100,800,5 ...
- chkconfig : No such file or directory
sys_version:12.04LTS For example: #chkconfig --level mysql on /sbin/insserv:No such file or director ...
- webim-界面细节调整
1)左侧css调整 3)界面和滚动条美化 8)界面
- SQLSERVER:计算数据库中各个表的数据量和每行记录所占用空间
转:http://www.cnblogs.com/lyhabc/p/3828496.html CREATE TABLE #tablespaceinfo ( nameinfo ) , rowsinfo ...
- (medium)LeetCode 207.Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- HDU 1043 八数码 Eight A*算法
Eight Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- <iOS>other linker flags[转]
包含静态库时候需要在Target的Other linker flags里面加上值:-objC,-all_load,-force_load 对于64位机子和iPhone OS应用 解决方法是使用-all ...