JavaScript Form Validation. JavaScript can be used to validate data in HTML forms
<script type="text/javascript">
function validate_all()
{
var frmReg=document.manageadmin;
if(frmReg.name.value.search(/\S/) == -1)
{
alert("Please enter name.");
frmReg.name.focus();
return false;
}
if(frmReg.textEmail.value.search(/\S/) == -1)
{
alert("Please enter Email.");
frmReg.textEmail.focus();
return false;
}
if(frmReg.textEmail.value.search(/\S/)!=-1)
{
var regex = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;
var temp_email = frmReg.textEmail.value ;
if (regex.exec(temp_email)==null)
{
alert("Invalid email format! Please Enter E-Mail Properly");
frmReg.textEmail.focus();
frmReg.textEmail.select();
return false;
}
}
if(frmReg.textTelephone.value.search(/\S/) == -1)
{
alert("Please enter telephone number.");
frmReg.textTelephone.focus();
return false;
}
if(isNaN(frmReg.textTelephone.value))
{
alert("Please enter only numbers as your Telephone number.");
frmReg.textTelephone.focus();
return false;
}
}
function reset_all()
{
var frmReg=document.manageadmin;
frmReg.reset();
}
</script>
<script type="text/javascript">
function validate_all()
{
var frmReg=document.manageadmin;
if(frmReg.name.value.search(/\S/) == -1)
{
alert("Please enter name.");
frmReg.name.focus();
return false;
}
if(frmReg.textEmail.value.search(/\S/) == -1)
{
alert("Please enter Email.");
frmReg.textEmail.focus();
return false;
}
if(frmReg.textEmail.value.search(/\S/)!=-1)
{
var regex = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;
var temp_email = frmReg.textEmail.value ;
if (regex.exec(temp_email)==null)
{
alert("Invalid email format! Please Enter E-Mail Properly");
frmReg.textEmail.focus();
frmReg.textEmail.select();
return false;
}
}
if(frmReg.textTelephone.value.search(/\S/) == -1)
{
alert("Please enter telephone number.");
frmReg.textTelephone.focus();
return false;
}
if(isNaN(frmReg.textTelephone.value))
{
alert("Please enter only numbers as your Telephone number.");
frmReg.textTelephone.focus();
return false;
}
}
function reset_all()
{
var frmReg=document.manageadmin;
frmReg.reset();
}
</script>