Home > Backend Development > PHP Tutorial > 问上正则的有关问题

问上正则的有关问题

WBOY
Release: 2016-06-13 12:52:16
Original
813 people have browsed it

问下正则的问题
用户名,可以输入中文也可以输入英文,
我要如何写正则来判断呢。
不能中英混输,
中文10个汉字以内。英文在30个字母以内都可以。
大家说说怎么用正则来处理这类问题呢?


------解决方案--------------------
中文 ===》\x{4e00}-\x{9fa5}

英文  a-z
因此可以:

/^([\x{4e00}-\x{9fa5}]{1,10}
------解决方案--------------------
[a-z]{1,30})$/iu
不知道你是否允许空格
<br />
	$pattern = "/^([\x{4e00}-\x{9fa5}]{1,10}<br><font color='#FF8000'>------解决方案--------------------</font><br>[a-z]{1,30})$/iu";<br />
	$test = array("这是中文","中文and英文","thisisenglish");<br />
	<br />
	foreach($test as $word){<br />
		echo $word;<br />
		echo " : ";<br />
		echo preg_match($pattern,$word);<br />
		echo "<br/>"; 		<br />
	}<br />
Copy after login

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