title: Is using multiple replaces in a JS function 'good' practice?
body: <p>I have an area of my site which allows a user to enter a custom URL. The rules of the URL are that it must be alphanumeric with the exception of the hyphen character. If a hyphen is used, it cannot be successive and cannot start (or end) the string.</p>
  
  <p>I use the following function to achieve this:</p>
  
  <pre><code>$('.url').bind("change keyup blur", function() {
       var url = $(this);
  
       url.val( url.val().replace(/[^A-z0-9-]/gi,'').replace(/-{2}/g,'-').replace(/^-/g,'') );
  });
  </code></pre>
  
  <p>The function works well but I am wondering if it is good practice or possible to combine the rules into a single replace statement.</p>
  
  <p>If successive hyphens (--) are used, a hyphen replaces it so I am thinking atleast 2 replace statements are needed.</p>
  
  <h2>EDIT</h2>
  
  <p>I am getting a lot of responses to the question in the form of 'here is code you should use' and while I appreciate it, the function I have is working. I ultimately was giving an example of what I meant by multiple replace statements on a single value and if it was good/bad practice to do such. </p>
  
  <p>I think giving the code hints or suggestion helps but not this is not a "how do I shorten this code" question.</p>