Regular Expression - Forbid string, of any size, that contains only one character repeatedly

时间:2015-11-12 10:49:46

标签: html regex html5 html-input

I am looking for a regex that will prevent the insertion of a string, with arbitrary size, that contains only one character repeatedly.

For example these strings are invalid

aaaaaaaaaa
222
bbbbbbbb
@@@@@@@@@@@@@@@@

but these are valid

aaaaaaa2
@@@@@@@@@@@@f
b2222 

I want it for an HTML5 text input:

<input type="text" class="form-control"  placeholder="name" pattern="...">

1 个答案:

答案 0 :(得分:3)

You can try the following:

^(?!^(.)\1+$).*$

It'd help if you also provide information about which tool you'll be using.