我在这里有一个jsfiddle- https://jsfiddle.net/3e91ropp/
我只需要找到一种不包括空格的方式来计算输入字段中字符的数量。
我需要验证电话号码字段至少有10个数字。
我可以使用length属性,但这会计算空格,我不想这样做。
$(function() {
$('button').on('click', function() {
console.log($('.field').val().length);
})
});
.wrap {
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrap">
<input class="field" type="text" />
<button>Click</button>
</div>
\s+
,它比\s
更好。 - Tushar\s
和\s+
,并查看完成匹配所需的步骤数。 - Tushar