我要创建需要核对姓名登记系统/带REGEX通等。(和喜欢),我已经这么远是:

//Check so numbers aren't first, such as 00foobar
preg_match('/^(?!\d)[a-z0-9]+$/iD',$usrname);
//Just simple check
preg_match('/^[a-zA-Z0-9]+$/',$psword);

但我必须做的IF语句愚蠢的事情,如:

if strlen($psword) > 30 || if (strlen($psword) < 4) ....

我将如何impliment在我的两个原始的正则表达式语句的长度检查?这让我很开心..

有帮助吗?

解决方案

相同,但使用单词和数字的\ w和\ d,但你可能想也包括像%!?/ ... etc...基本符号

preg_match('/^[\w\d]{4,30}$/',$psword);

{n,v}将验证最小n和前最大V族元素。

A{2,3}将验证为AAAAA。你可以看看更多的引用有

在以同样的方式,如果你想只设置最小百通{n,}会做到这一点。例如:

preg_match('/^[\w\d]{4,}$/',$psword);

其他提示

我想这应该做的伎俩:

  

的preg_match( '/ ^ [A-ZA-Z0-9] {4,30} $ /',$ psword);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top