<script language="javascript" type="text/javascript">
function validate() {
if (document.getElementById("<%=txtFirstName.ClientID%>").value == "") {
alert("Name Field can not be blank");
document.getElementById("<%=txtFirstName.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtEmail.ClientID%>").value == "") {
alert("Email Field can not be blank");
document.getElementById("<%=txtEmail.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtPhone.ClientID%>").value == "") {
alert(" Phone Field can not be blank");
document.getElementById("<%=txtPhone.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtEmergencyContact.ClientID%>").value == "") {
alert("Emergency Contact Field can not be blank");
document.getElementById("<%=txtEmergencyContact.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtAge.ClientID%>").value == "") {
alert("Age Field can not be blank");
document.getElementById("<%=txtAge.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtPreferred.ClientID%>").value == "") {
alert("Preferred Partner Field can not be blank");
document.getElementById("<%=txtPreferred.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtPhone.ClientID%>").value == "") {
alert("Mobile No is not valid");
document.getElementById("<%=txtPhone.ClientID%>").focus();
return false;
}
var digits = /^([0-9]{10})$/;
var digitsid = document.getElementById("<%=txtPhone.ClientID %>").value;
var digitsArray = digitsid.match(digits);
var temp;
if (digitsArray == null) {
alert("Your mobile seems incorrect. Please try again.");
document.getElementById("<%=txtPhone.ClientID %>").focus();
return false;
}
var digits = /^([0-9]{10})$/;
var digitsid = document.getElementById("<%=txtEmergencyContact.ClientID %>").value;
var digitsArray = digitsid.match(digits);
var temp;
if (digitsArray == null) {
alert("Your Emergency Contact seems incorrect. Please try again.");
document.getElementById("<%=txtEmergencyContact.ClientID %>").focus();
return false;
}
return true;
}
</script>
In Submit Button We have
<asp:Button CssClass="button" ID="btnNameEmail" runat="server" Text="Submit" OnClick="btnNameEmail_Click" OnClientClick ="return Validate(this)" />
Call the JavaScript Function
function validate() {
if (document.getElementById("<%=txtFirstName.ClientID%>").value == "") {
alert("Name Field can not be blank");
document.getElementById("<%=txtFirstName.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtEmail.ClientID%>").value == "") {
alert("Email Field can not be blank");
document.getElementById("<%=txtEmail.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtPhone.ClientID%>").value == "") {
alert(" Phone Field can not be blank");
document.getElementById("<%=txtPhone.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtEmergencyContact.ClientID%>").value == "") {
alert("Emergency Contact Field can not be blank");
document.getElementById("<%=txtEmergencyContact.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtAge.ClientID%>").value == "") {
alert("Age Field can not be blank");
document.getElementById("<%=txtAge.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtPreferred.ClientID%>").value == "") {
alert("Preferred Partner Field can not be blank");
document.getElementById("<%=txtPreferred.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtPhone.ClientID%>").value == "") {
alert("Mobile No is not valid");
document.getElementById("<%=txtPhone.ClientID%>").focus();
return false;
}
var digits = /^([0-9]{10})$/;
var digitsid = document.getElementById("<%=txtPhone.ClientID %>").value;
var digitsArray = digitsid.match(digits);
var temp;
if (digitsArray == null) {
alert("Your mobile seems incorrect. Please try again.");
document.getElementById("<%=txtPhone.ClientID %>").focus();
return false;
}
var digits = /^([0-9]{10})$/;
var digitsid = document.getElementById("<%=txtEmergencyContact.ClientID %>").value;
var digitsArray = digitsid.match(digits);
var temp;
if (digitsArray == null) {
alert("Your Emergency Contact seems incorrect. Please try again.");
document.getElementById("<%=txtEmergencyContact.ClientID %>").focus();
return false;
}
return true;
}
</script>
In Submit Button We have
<asp:Button CssClass="button" ID="btnNameEmail" runat="server" Text="Submit" OnClick="btnNameEmail_Click" OnClientClick ="return Validate(this)" />
Call the JavaScript Function