我有一個輸入只匹配字母,但由於某些原因,下劃線也算作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