validation using javascript.

4 views
Skip to first unread message

Er. Manish Insan

unread,
Mar 14, 2011, 7:09:53 AM3/14/11
to DotNetProfessionals-Group
<script type="text/javascript">

function validate()
{

// for check that text box is fill or empty.

if (document.getElementById("<%=txtName.ClientID%>").value=="")

{
alert("Name Feild can not be blank");
document.getElementById("<%=txtName.ClientID
%>").focus();
return false;
}
if(document.getElementById("<%=txtEmail.ClientID %>").value=="")
{
alert("Email can not be blank");
document.getElementById("<%=txtEmail.ClientID
%>").focus();

return false;
}

// check that email address is valid or not.

var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|
[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
var emailid=document.getElementById("<%=txtEmail.ClientID
%>").value;
var matchArray = emailid.match(emailPat);
if (matchArray == null)
{
alert("Your email address seems incorrect. Please
try again.");
document.getElementById("<%=txtEmail.ClientID
%>").focus();
return false;
}
if(document.getElementById("<%=txtCourse.ClientID
%>").value=="")
{
alert("Cousrse field can not be blank");
document.getElementById("<%=txtCourse.ClientID
%>").focus();
return false;
}


return true;
}
</script>
Reply all
Reply to author
Forward
0 new messages