我无法将此正则表达式作为字母数字。此正则表达式满足我的所有要求,但它不是字母数字,即它必须验证输入的值是否为字母数字。正则表达式低于
^
(?!(.)\1+$)
(?!.*([a-zA-Zа-яА-Я0-9ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞߟàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0-9]\d)\2{3})
(?!.*([ '"-])\3)(?![a-zA-Zа-яА-ЯÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞߟàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0-9\d]*\W{2})
(?=.*[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞߟàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿè-ÿ0-9\d])
(?!.*[Pp]+(OST|ost)*\.*\s*[Oo0]*(FFICE|ffice)*\.*\s*[Bb]*\.*\s*[Oo0]*\.*\s*[Xx].*)
[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞߟàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿè-ÿ0-9\d\ *"(:,\/.\\;&)\[\]_+#'-]{3,40}
$
它应该接受以下所有标准。它只满足所有标准“它必须至少包含3个强制字母数字字符 特殊字符“尚未填满。 正则表达式应该满足以下条件:
验收标准是:
Haaadoop 123
A-B 123
123 âãäåæçèéêëìíî
нОоСсТт 123
123 нОоСсТт
нОр123Тт
123 Haaadoop
123 A-B
âãäåæçèéêëìíî 123
âãäåæ123çèéêëìíî
它不应该接受:
Haaaaadoop 123
A- -B 123
A- -B 123
A-&B123
AAA
abcd
123
123 Haaaaadoop
123 A- -B
123 A- -B
2 a
答案 0 :(得分:0)
嗯,这是最终的正则表达式:
^
(?!(?:[\d ]+|[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ ]+)$) # - no digit-only/alpha-only input (with spaces)
(?!(.)\1+$) # no same char input
(?!.*([a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9])\2{3}) # no same consecutive 4 alphanum chars
(?!.*[^a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]{2}) # no 2 consecutive non-alphanum chars
(?=(?:[^a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]*[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]){3}) # at least 3 alphanum chars in input
(?!.*[Pp]+(OST|ost)*\.*\s*[Oo0]*(FFICE|ffice)*\.*\s*[Bb]*\.*\s*[Oo0]*\.*\s*[Xx].*) # No POST OFFICE BOX in input
[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9\ *"(:,\/.\\;&)\[\]_+#'-]{3,40} # 3 to 40 letters, digits and some special chars
$
一个班轮:
/^(?!(?:[\d ]+|[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ ]+)$)(?!(.)\1+$)(?!.*([a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9])\2{3})(?!.*[^a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]{2})(?=(?:[^a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]*[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]){3})(?!.*[Pp]+(OST|ost)*\.*\s*[Oo0]*(FFICE|ffice)*\.*\s*[Bb]*\.*\s*[Oo0]*\.*\s*[Xx].*)[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9 *"(:,\/.\\;&)[\]_+#'-]{3,40}$/
请参阅regex demo
注意:
[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ]
ё
和Ё
不属于а-я
和А-Я
范围,必须单独添加
var good = [ 'Haaadoop 123','A-B 123','123 âãäåæçèéêëìíî','нОоСсТт 123','123 нОоСсТт','нОр123Тт','123 Haaadoop','123 A-B','âãäåæçèéêëìíî 123','âãäåæ123çèéêëìíî'];
var bad = ['Haaaaadoop 123','A- -B 123','A- -B 123','A-&B123','AAA','abcd','123','123 Haaaaadoop','123 A- -B','123 A- -B','2 a', 'asdasd asdasdasdsadd', 'sdasd asdfsdafasdf', 'asdfasdf sdfdasfdsaf','132 123'];
var rx = /^(?!(?:[ \d]+|[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ ]+)$)(?!(.)\1+$)(?!.*([a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9])\2{3})(?!.*[^a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9\n]{2})(?=(?:[^a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]*[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9]){3})(?!.*[Pp]+(OST|ost)*\.*\s*[Oo0]*(FFICE|ffice)*\.*\s*[Bb]*\.*\s*[Oo0]*\.*\s*[Xx].*)[a-zA-ZÀ-ÖØ-ߟà-çа-яА-ЯЁёè-ÿ0-9\ *"(:,\/.\\;&)\[\]_+#'-]{3,40}$/;
document.body.innerHTML += "<br/>------ Valid ------<br/>";
for (var s = 0; s < good.length; s++) { // Demo
document.body.innerHTML += "Testing \"<i>" + good[s] + "</i>\"... ";
document.body.innerHTML += "Matched: <b>" + rx.test(good[s]) + "</b><br/>";
}
document.body.innerHTML += "<br/>------ Invalid ------<br/>";
for (var s = 0; s < bad.length; s++) { // Demo
document.body.innerHTML += "Testing \"<i>" + bad[s] + "</i>\"... ";
document.body.innerHTML += "Matched: <b>" + rx.test(bad[s]) + "</b><br/>";
}