jQuery - count number of characters in a input field excluding spaces

I have a jsfiddle here - https://jsfiddle.net/3e91ropp/

I simple need a way to count the number of characters in an input field excluding spaces.

I need to validate a phone number field to have at least 10 numbers.

I can use the length property but that counts spaces which I don’t want to do

$(function() {
  $('button').on('click', function() {
.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" />


You could remove the spaces using the .replace() method:

Updated Example

$('.field').val().replace(/\s+/g, '').length