Javascript
HOW TO VALIDATE TEXTBOX IN JAVASCRIPT?
Here is a very simple text box validation from javascript. This will validate empty values in html textbox. Copy and Paste this code after the <header> .
<script type="text/javascript">
function validateform(regform)
{
if (""==document.forms.regform.uname.value){
alert("Please enter your desired username!.");
document.getElementById('uname').focus();
return false;
}
if (""==document.forms.regform.upassword.value){
alert("Please enter your desired password!.");
document.getElementById('upassword').focus();
return false;
}
if (""==document.forms.regform.upassword2.value){
alert("Please Re-Enter your password!");
document.getElementById('upassword2').focus();
return false;
}
if (""==document.forms.regform.department.value){
alert("Please enter your department!.");
document.getElementById('department').focus();
return false;
}
if (""==document.forms.regform.email.value){
alert("Please enter your email address!. (Personal not Corporate)");
document.getElementById('email').focus();
return false;
}
return true;
}
</script>
function validateform(regform)
{
if (""==document.forms.regform.uname.value){
alert("Please enter your desired username!.");
document.getElementById('uname').focus();
return false;
}
if (""==document.forms.regform.upassword.value){
alert("Please enter your desired password!.");
document.getElementById('upassword').focus();
return false;
}
if (""==document.forms.regform.upassword2.value){
alert("Please Re-Enter your password!");
document.getElementById('upassword2').focus();
return false;
}
if (""==document.forms.regform.department.value){
alert("Please enter your department!.");
document.getElementById('department').focus();
return false;
}
if (""==document.forms.regform.email.value){
alert("Please enter your email address!. (Personal not Corporate)");
document.getElementById('email').focus();
return false;
}
return true;
}
</script>
Good Luck and Enjoy using this code.