Validate textbox using textbox id as parameter.
========================================================================
<script type="text/javascript">
function checkTextField(field) {
var _txtSearch = document.getElementById(field).value;
if (_txtSearch == "") {
alert("Please enter your search text.");
document.getElementById(field).focus();
return false;
}
}
</script>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/searchbar.jpg" OnClientClick="return checkTextField('txt_search')"
OnClick="ImageButton1_Click" Style="width: 34px" />
========================================================================
<script type="text/javascript">
function Validation() {
var mobrange = /^[0-9]{10}$/;
var exp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
var name = document.getElementById('<%=txt_name.ClientID%>').value;
var email = document.getElementById('<%= txt_email.ClientID %>').value;
var contact = document.getElementById('<%=txt_phone.ClientID%>').value;
if (name == "") {
alert("Please Enter Your Name.");
document.getElementById('<%=txt_name.ClientID%>').focus();
return false;
}
if (email == "") {
alert('Email field can not be blank');
document.getElementById("<%=txt_email.ClientID%>").focus();
return false;
}
if (exp.test(email) == false) {
alert('Email should be in proper format (eg: xyx@gmail.com)');
document.getElementById("<%=txt_email.ClientID%>").focus();
return false;
}
if (contact == "") {
alert("Please Enter Your Mobile Number.");
document.getElementById("<%=txt_phone.ClientID%>").focus();
return false;
}
if (mobrange.test(contact) == false) {
alert("Mobile number is not valid.");
document.getElementById("<%=txt_phone.ClientID%>").focus();
return false;
}
if (contact.length > 10 || contact.length < 10) {
alert("Mobile number is not valid.");
document.getElementById("<%=txt_phone.ClientID%>").focus();
return false;
}
}
</script>
No comments:
Post a Comment