jQuery Validation - IBAN

Christoph C. picture Christoph C. · Aug 25, 2015 · Viewed 7.8k times · Source

I saw that there are a few plugins available on the internet for checking if an IBAN is correct or not. I found the following IBAN and wanted to use it for my form:

https://github.com/jzaefferer/jquery-validation/blob/master/src/additional/iban.js

I downloaded the .js file and included it into my .php page like this:

<script src="js/iban.js"></script>

My form looks like this:

<form method="POST" action="update_profile.php" id="editprofile" class="form-horizontal form-label-left">
   <div class="form-group">
     <label class="control-label col-md-3 col-sm-3 col-xs-12">Bank:</label>
      <div class="col-md-9 col-sm-9 col-xs-12">
       <input type="text" class="form-control" name="bank" value="<?php echo $_SESSION['data']['bankaccount']; ?>">
      </div>
   </div>

   <div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">Inhaber:</label>
     <div class="col-md-9 col-sm-9 col-xs-12">
      <input type="text" class="form-control" name="inhaber" value="<?php echo $_SESSION['data']['bankowner']; ?>">
     </div>
   </div>

   <div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">IBAN:</label>
     <div class="col-md-9 col-sm-9 col-xs-12">
      <input type="text" class="form-control" name="iban" id="iban" value="<?php echo $_SESSION['data']['iban']; ?>" required>
     </div>
   </div>

   <div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">BIC:</label>
     <div class="col-md-9 col-sm-9 col-xs-12">
      <input type="text" class="form-control" name="bic"  value="<?php echo $_SESSION['data']['bic']; ?>">
     </div>
    </div>
<button type="submit" name="update" value="update" class="btn btn-warning btn-lg btn-block">Edit</button>
    </form>
    <script>
    $("#editprofile").validate();
    </script>

Now if I click the edit button, my form gets send but the iban is not validated. I can even enter a wrong IBAN. What I am doing wrong? This is my first time that I include a plugin/.js file into my form. I am something missing but what is it?

Thanks, Chris

Answer

Max picture Max · Apr 23, 2016

If you are using jquery.validate with IBAN plugin just set attribute data-rule-iban="true"

<input data-rule-iban="true" id="IBAN" class="form-control" placeholder="IBAN *" type="text" required  tabindex="10">