PHP: Simple regular expressions to match length?

*爱你&永不变心* 提交于 2019-12-05 00:49:58
RageZ

same but using the \w and \d for word and digits, but you might want also to include basic symbols like %!?/ ... etc...

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

the {n,v} would validate for minimum n and maximum v elements before.

like A{2,3} would validate for AA and AAA. you can take a look there for more references

On the same fashion if you want only to set the minimum of patern {n,} would do it. For example:

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

I think this should do the trick:

preg_match('/^[a-zA-Z0-9]{4,30}$/',$psword);

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!