Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
//IsValidNIF function code (...)
$('form').on('submit', function() {
var input = $('input');
var info = $('#infoSubmit');
var inName = $('input#name-of-company');
var inNif = $('input#nif');
var inAi = $('input#annual-income');
var inEmp = $('input#employees');
var nameReg = /^\S.{0,58}\S$/;
var aiReg = /^([0-9]{3,15})$/;
var empReg = /^([0-9]{1,10})$/;
if ( !nameReg.test( inName.val() ) ) {
info.text('please enter a valid name');
inName.addClass('wrongInput');
inName.focus();
} else if( !IsValidNIF( inNif.val() ) ) {
input.removeClass('wrongInput');
info.text('');
inNif.focus();
info.text('please enter a valid nif');
inNif.addClass('wrongInput');
inNif.focus();
} else if( !aiReg.test( inAi.val() ) ) {
input.removeClass('wrongInput');
info.text('');
inAi.focus();
info.text('please enter a valid annual income');
inAi.addClass('wrongInput');
inAi.focus();
} else if( !empReg.test( inEmp.val() ) ) {
input.removeClass('wrongInput');
info.text('');
inEmp.focus();
info.text('please enter a valid number of employees');
inEmp.addClass('wrongInput');
inEmp.focus();
} else {
input.removeClass('wrongInput');
info.text('');
$.post('save.php', $(this).serialize(), function() {
$(infoSubmit).text('Data submitted, thank you!');
inName.val('');
inNif.val('');
inAi.val('');
inEmp.val('');
});
}
return false;
});
this only gives an error class to a field when I click submit.which input ?
<form id="myForm" action="#" method="get">
<label for="name-of-company">Company Name:</label>
<input type="text" name="name-of-company" value="" id="name-of-company" />
<label for="annual-income">NIF:</label>
<input type="text" name="nif" value="" id="nif" />
<label for="annual-income">Annual Income:</label>
<input type="text" name="annual-income" value="" id="annual-income" />
<label for="employees">Employees:</label>
<input type="text" name="employees" value="" id="employees" />
<input type="submit" name="submit" value="Submit" id="submitBtn"/>
</form>
<span id="infoSubmit"></span>
$.validator.methods.IsValidNIF = function(value, element, param) {
// Perform custom validation and return true or false
return value === '' || /^([0-9]{10})$/.test(value);
};
$("#myForm").validate({
rules: {
nif: {
IsValidNif: true
}
},
messages: {
nif: {
isValidNif: "Enter some information before proceeding"
}
},
submitHandler: function(form)
{
// do the work to submit this form
}
});
<form id="myForm" action="" method="post">
<label for="nameCompany">Company Name:</label>
<input type="text" name="nameCompany" value="" id="nameCompany" />
<label for="nif">NIF:</label>
<input type="text" name="nif" value="" id="nif" />
<label for="annualIncome">Annual Income:</label>
<input type="text" name="annualIncome" value="" id="annualIncome" />
<label for="employees">Employees:</label>
<input type="text" name="employees" value="" id="employees" />
<input type="submit" name="submit" value="Submit" id="submitBtn"/>
</form>
body {
font-family: Calibri;
}
#myForm {
/background: blue;
/overflow: visible;
}
label {
width: 120px;
margin-right: 8px;
float: left;
text-align: right;
color: blue;
}
input {
display: block;
}
#submitBtn {
margin-left: 225px;
margin-top: 5px;
overflow: visible;
}
on the right of the inputs to display errors
#commentForm label.error, #commentForm input.submit {
margin-left: 10px;
width: auto;
display: inline;
}
Change commentForm to your form IDMy main job is in the 3D fieldWhich company you work ? I worked about 5 years in a 3D company in lisbon.
Try this
http://stackoverflow.com/questions/7925368/how-to-fade-out-error-prompts-with-validation-engine-plug-in-for-jquery?answertab=active#tab-top
Não, eu não trabalho em 3D. Eu era responsável por todo parque informatico dessa empresa (Arqui300 e Arqui300 Academy).
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
http://stackoverflow.com/questions/7925368/how-to-fade-out-error-prompts-with-validation-engine-plug-in-for-jquery?answertab=active#tab-top
Não, eu não trabalho em 3D. Eu era responsável por todo parque informatico dessa empresa (Arqui300 e Arqui300 Academy).