这个涉及正则的简单功能如何实现

WBOY
Release: 2016-06-13 13:49:41
Original
894 people have browsed it

这个涉及正则的简单功能怎么实现?
判断一个字符串(这个字符串只能包含下面三种字符)
1. 26个英文字母
2. “0,1,2,3,4,5,6,7,8,9”十个数字
3. “-”(英文中的连词号)

------解决方案--------------------
$str="/[^0-9a-zA-Z]/i";
------解决方案--------------------
汗楼撒谎那个掉了“―”
$str="/[^0-9a-zA-Z_]/i";
------解决方案--------------------
楼上的是错的。
如果是判断不存在的,那么 '-' 这个不算?

有 i 修饰,又何需 a-zA-Z 呢?

/^[a-z0-9-]+$/i
------解决方案--------------------

PHP code
preg_match('/[-a-z0-9]+/i',$str); //$str 是你要匹配的字符串
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
<?php $str="jsd-fowfmf564c-s1f23";
$pattern='/^[a-z0-9-]+$/i';//用的楼上的楼上
preg_match($pattern,$str,$result);
if($result)
{
    echo "匹配";
};
?>
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
PHP code
preg_match('/[-a-z0-9]+/i',$str); //$str 是你要匹配的字符串

------解决方案--------------------
探讨

引用:

PHP code
$str="jsd-fowfmf564c-s1f23";
$pattern='/^[a-z0-9-]+$/i';//用的楼上的楼上
preg_match($pattern,$str,$result);
if($result)
{
echo "匹配";
};
?>
用js怎么实现?
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!