Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi frnds,

on my webpage i have a registration form to register.

I need to validate these textboxes using javascript on submit button click.

total i have 6 textboxes, i need to validate on submit button click using Javascript.



TxtUserName ---- Required field

TxtPassword --- Required Field

TxtEmailAddress ---- Email address must be Required and it must be Valid as test@test.com

TxtRetypeEmailAddress --- Retype Email address must be Required and it must be Valid as test@test.com & it must match the First Email Address

TxtLocation -- Required Field

TxtMobileNo --- Required Filed & only Numbers are accepted & only 10 digits.


and finally, i have submit button.
SUBMIT BUTTON

Please can you help me, how to validate all these using javascript.

thanks in advance.....
Posted

 
Share this answer
 
Comments
HYD Webdeveloper 15-Jul-13 6:51am    
am unable to understand the links code. am fresher.

Please can anybody will write Javascript for my question. I need it urgent.

Thanks for ever.
Dholakiya Ankit 15-Jul-13 7:27am    
its javascript dude...........
HTML
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
First name: <input type="text" name="fname">
<input type="submit" value="Submit">
</form>

JavaScript
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}
</script>
</head>
 
Share this answer
 
v4
Required field:

XML
<asp:RequiredFieldValidator ID="RFUserName" runat="server" ControlToValidate="TxtUserName"
                                  Display="Dynamic" ForeColor="Red" ErrorMessage="Enter user name."></asp:RequiredFieldValidator>


Email Address:

XML
<asp:RegularExpressionValidator ID="regexEmailValid1" runat="server"
                      ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                      ControlToValidate="TxtEmailAddress" ErrorMessage="Invalid Email Format" Display="None"></asp:RegularExpressionValidator>



Function for mobile number validation.Call this function on submit button:

C#
function IsMobileNumber(TxtMobileNo ) {
    var mob = /^[1-9]{1}[0-9]{9}$/;
    var txtMobile = document.getElementById(txtMobId);
    if (mob.test(txtMobile.value) == false) {
        alert("Please enter valid mobile number.");
        txtMobile.focus();
        return false;
    }
    return true;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900