ABN Number Validation with javascript and html Full Example and Source Code

1.)Source Code Part 1 Html abn number validation
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<div class="container">
<div class="row">

<div>
<form id="register_form" class="forms-sample" method="post" action="register" enctype="multipart/form-data">
<div class="form-group">
<label >ABN Number</label>
<input id="contact_abn_no" type="text" name="abn_no" class="form-control" value="" placeholder="ABN Number">


<span class="text-danger" style="font-size:12px;display:none;">{{ $errors->first('abn_no') }}</span>

</div>
<br/>
<div>
<button style="margin-top:0px;" type="submit" class="btn btn-primary btn-lg btn-block btn-block_top_margin btnsubload">Submit</button>
</div>


</form>
</div>



</div>
</div>

 
 
2.)Source Code Part 2 Javascript abn number validation

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.js"></script>

<script type="text/javascript">

$.ajaxSetup({

headers: {

'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

}

});

$(function() {
$("#contact_abn_no").mask("00 000 000 000", {
onChange: function () {
console.log($('#contact_abn_no').val());
}
});
});




$(function(){
$("#register_form").validate({
rules: {


"abn_no": {
checkAbn : true,
required: true

}



},
messages: {

"abn_no": {
required: "Please Enter ABN Number"
}

},
highlight: function (element, errorClass, validClass) {

$("#loading").css("visibility", "hidden");
return false;
$("#loading").css("visibility", "visible");
},
errorElement: 'span',
submitHandler: function (form) {
form.submit();
}
});



$.validator.addMethod("checkAbn", function(value, element) {


var abn_val = $("#contact_abn_no").val()
if (abn_val.trim() != '') {
var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
if (abn_val.length == 14) {
//remove spaces from string
abn_val = abn_val.replace(/\s+/g, '');
// strip anything other than digits
abn_val = abn_val.replace("/[^\d]/", "");
// check length is 11 digits
if (abn_val.length == 11) {
// apply ato check method
var sum = 0;
for (var i = 0; i < 11; i++) {
var digit = abn_val[i] - (i ? 0 : 1);
var sum = sum + (weights[i] * digit);
}
return ((sum % 89) == 0);
} else {
return false;
}
}
} else {
return true;
}

// return true;
}, "ABN number not vailid.");

})


</script>



 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Comments

Popular posts from this blog

RGPV CSE 8th Semester Soft computing Notes and Lectures

श्रीदेवी की मौत | Shree Devi Bollywood Actress Death

Online Earning:Become an online seller