<form id="frm_subscription">
<div class="form-group">
<div class="row">
<div class="col-md-6 col-xs-12">
<input type="text" class="form-control form-input border required" name="business_name" placeholder="Business Name *" required="true">
</div>
<div class="col-md-6 col-xs-12">
<input type="text" class="form-control form-input" name="business_address" placeholder="Business Address">
</div>
</div>
</div>
</form>
function validate(formId) {
let valid = true;
$.each(formId, function(i, field) {
$("[name='" + field.name + "']").prev('.text-danger').remove();
if (field.value == "" && $("[name='" + field.name + "']").prop('required')) {
valid = false;
$("[name='" + field.name + "']").css({ "border": "1px solid #ff000087" });
$("[name='" + field.name + "']").before('<span class="text-danger">This field is required *</span>');
}
});
return valid;
}
if (!validate($("#frm_subscription").serializeArray())) { return; }