The code will be helpful in validating data entry forms such as: user registration, user creati on. validate_required is used by all other functions
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=='')
{
alert(alerttxt);return false
}
else {return true}
}
}
function validateTicketCreateForm(thisform)
{
with (thisform)
{
if (validate_required(type,'Type must be filled out!')==false)
{type.focus();return false}
if (validate_required(subject,'Subject must be filled out!')==false)
{subject.focus();return false}
}
}
function validate_customer_create_form(thisform)
{
with (thisform)
{
if (validate_required(firstName,'First name must be filled out!')==false)
{firstName.focus();return false}
if (validate_required(lastName,'Last name must be filled out!')==false)
{lastName.focus();return false}
if (validate_required(phone,'Phone must be filled out!')==false)
{phone.focus();return false}
}
}
function validateUserCreateForm(thisform)
{
with (thisform)
{
if (validate_required(firstName,'First name must be filled out!')==false)
{firstName.focus();return false}
if (validate_required(lastName,'Last name must be filled out!')==false)
{lastName.focus();return false}
if (validate_required(shortName,'Short name must be filled out!')==false)
{shortName.focus();return false}
if (validate_required(username,'Username must be filled out!')==false)
{username.focus();return false}
if (validate_required(password,'Password must be filled out!')==false)
{password.focus();return false}
if (password.value.length < passwordLength.value) {alert("Password must be
at least " + passwordLength.value +" char long");
password.focus();return false}
if (validate_required(password2,'Please re-enter password!')==false)
{password2.focus();return false}
if (password.value != password2.value)
{
alert("Password did not match");
password2.focus();
return false
}
}
}
From: http://sitestree.com/?p=3475
Categories:JavaScript
Tags:
Post Data:2016-07-09 20:36:29
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada
