title: How to clear jasny input mask before using in Laravel validator?
body: <p>I have a form field to get mobile number of users:</p>
  
  <pre><code>&lt;input class="form-control" name="mobile" data-mask="0999 999 9999" type="text" id="mobile" /&gt;
  </code></pre>
  
  <p>I used <a href="http://www.jasny.net/bootstrap/javascript/#inputmask" rel="nofollow">jasny input mask</a> to guide users for entering data but I need to save mobile number in format <strong>999999999</strong> into database (Without 0 and spaces).</p>
  
  <p>As I use ajax to send data to server by serialize() function, I don't want to use client side script to change entered value (I have many such form fields) unless by changing or adding a function or method to jasny input mask to use on all such fields!</p>
  
  <p>I get the entered value server-side and I want to assign it to a model attribute in Laravel 5 so in user model I declared an accessor and a mutator to set and get mobile number:</p>
  
  <pre><code>public function setMobileAttribute($value){
      $value = substr(str_replace(" ","",$value),1);
      $this-&gt;attributes['mobile'] = $value;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public function getMobileAttribute($value){
      return '0'.substr($value,0,3).' '.substr($value,3,3).' '.substr($value,6,4);
  }
  </code></pre>
  
  <p>It works nice but when I want to use Laravel validation to indicate it's a unique field, it doesn't work.
  Peace of code is like:</p>
  
  <pre><code>class UserController extends Controller {
  
      protected $rules = ['mobile' =&gt; 'required|unique:users'];
      public function store(Request $request){
          $validator = Validator::make($request-&gt;all(), $this-&gt;rules);
          if ($validator-&gt;fails()){
              return response()-&gt;json([
                  'success' =&gt; false,
                  'errors' =&gt; $validator-&gt;getMessageBag()-&gt;toArray()
              ]);
          }
          // codes to store user...
      }
  }
  </code></pre>
  
  <p>It cause to error:
  <em>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry</em> </p>