Users often send many meaningless characters such as "Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
Is there any way to prohibit it? Either js or php is fine.
Thanks
我想大声告诉你2017-06-29 10:10:06
Regular judgment
var re = /(.){3,}/u; // 匹配同一个字符4次以上
re.test(str); // true = 同一字符4次或以上
preg_match('/(.){3,}/u', $str); // 1 = 同一个字4次或以上
Send a JS test picture:
Note:
modifier after the regular is used to support Unicode wide characters
{3,}
means matching 3 times or more. Since the previous (.)
has already been matched once, the entire limited number is 1 greater than this number. In addition, this number can be changed according to your own needs.