我有一个输入只匹配字母,但由于某些原因,下划线也算作OK符号。JQuery - 匹配中的下划线()
$(document).ready(function() {
$('#first_name').bind('input', function() {
if (!$(this).val().match("^[A-zА-я^_]{3,}$")) {
$('#first_name').css('background-color', 'rgb(250,171,192)');
$('#first_name').css('border-color', 'rgb(180,86,109)');
}
else {
$('#first_name').css('background-color', 'rgb(193,256,159)');
$('#first_name').css('border-color', 'rgb(31,122,23)');
}
});
});
<input type="text" id="first_name" />
我后来添加了“^ _”条件,但它在没有它的情况下也是一样的。
我刚刚意识到反斜杠也是这样。 – 2014-10-07 08:37:06