"KTP INA Verification with date"
Bootstrap 3.0.0 Snippet by elkhunsu

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <form class="form-horizontal application-form"> <fieldset> <!-- Form Name --> <legend>Form Name</legend> <!-- Multiple Radios --> <div class="form-group"> <label class="col-md-4 control-label" for="radios">Multiple Radios</label> <div class="col-md-4"> <div class="radio"> <label for="gender1"> <input type="radio" name="radios" id="gender1" value="male" checked="checked"> MALE </label> </div> <div class="radio"> <label for="gender2"> <input type="radio" name="radios" id="gender2" value="female"> FEMALE </label> </div> </div> </div> <!-- Text input--> <div class="form-group"> <label class="col-md-4 control-label" for="identification_number">KTP</label> <div class="col-md-5"> <input id="identification_number" name="identification_number" type="text" placeholder="ktp number" class="form-control input-md" required="" data-odd> <span class="help-block">Input KTP number</span> </div> </div> <!-- Text input--> <div class="form-group"> <label class="col-md-4 control-label" for="date_of_birth">dob</label> <div class="col-md-4"> <input id="date_of_birth" name="date_of_birth" type="text" placeholder="DD/MM/YYYY" class="form-control input-md"> <span class="help-block">date of birth</span> </div> </div> <!-- Button --> <div class="form-group"> <label class="col-md-4 control-label" for="singlebutton"></label> <div class="col-md-8"> <button id="apply" name="singlebutton" class="btn btn-primary">Apply</button> </div> </div> </fieldset> </form>
$('.application-form').validator({ custom:{ 'odd' : function($el){ var matchValue = $el[0].value // foo return ktpValidator(matchValue); } } }).on('submit', function(){ if (tindakan.isDefaultPrevented()) { //prevent from submission } else { alert('sukses'); } }); function ktpValidator(matchValue){ var ktpVal = $("[name='identification_number']").val(); if(ktpVal.length === 16 && ktpVal === matchValue){ var dob = $("[name='date_of_birth']").val().split("/"); var cekDateID = $("input[name='gender']:checked").val() === 'female' ? parseInt(dob[0]) + 40 : dob[0]; var dobResult = String(cekDateID).concat(dob[1], dob[2].slice(2)) var dateKtp = ktpVal.slice(6, 12); if(dobResult !== dateKtp){ return "Data KTP Anda Tidak Valid"; } } else { return "Input KTP 16 Digit Anda"; } }

Related: See More


Questions / Comments: