English 中文(简体)
RegEx检查一个字符连续出现的3次或3次以上
原标题:RegEx to check 3 or more consecutive occurrences of a character
  • 时间:2011-02-07 07:06:26
  •  标签:
  • php
  • regex

我想检查一个输入字符串来验证一个正确的文本。

a.我希望用户允许书写字母数字字符,包括句点、逗号、连字符和圆括号()

b.但是,我不希望用户一起输入3位或3位以上数字的数字。例如:12是允许的,而185是不允许的。

c.我不希望用户输入诸如“…………..”、“----------------”、“aaaaaaaaaa”或“bbbbbbbb”等字符串。

请建议使用相同的正则表达式。

最佳回答

您可以使用正则表达式:

(?!.*(.)1{2})^[a-zA-Z0-9.,()-]*$

它使用负前瞻(?!.*(.)1{2})来确保任何字符不存在3个重复的组。

然后,它使用正则表达式^[a-zA-Z0-9.,()-]*$来确保字符串仅由字母、数字、句点、逗号、括号和连字符组成。

悬钩子链接

问题回答

Most regex libs support the folloing: /(.)1{2,}/

其中1是反向引用





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签