Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Issue implementing password validation

$
0
0

Good Day

I am using the popular https://github.com/jzaefferer/jquery-validation validation plugin for my ASP.NET form.

Now you will see that inside my <fieldset> elements, I have the original code of the plugin, and I am applying the form controls to my asp controls one by one. Now everything seems to work except for password...

I have set the name and type as password for my asp password controls, but the validation does not work there...Notice that the ID is not #password but neither did I copy the original form ID's for the other controls(such as email)...So it can't be the ID can it?

Any suggestions? Note, I do not want to change the ID's on my asp controls... 

<%@ Page Title="" Language="C#" MasterPageFile="~/CardVault.Master" AutoEventWireup="true" CodeBehind="SignupPersonal.aspx.cs" Inherits="CardVault.SignupPersonal" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function () { alert("submitted!"); }
});

$().ready(function () {

// validate signup form on keyup and submit
$("form").validate({
rules: {
firstname: "required",
lastname: "required",
username: {
required: true,
minlength: 2
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#TextBoxConfirmPassword"
},
email: {
required: true,
email: true
},
topic: {
required: "#newsletter:checked",
minlength: 2
},
agree: "required"
},
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
username: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
confirm_password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long",
equalTo: "Please enter the same password as above"
},
email: "Please enter a valid email address",
agree: "Please accept our policy"
}
});

// propose username by combining first- and lastname
$("#username").focus(function () {
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
if (firstname && lastname && !this.value) {
this.value = firstname + "." + lastname;
}
});

//code to hide topic selection, disable for demo
var newsletter = $("#newsletter");
// newsletter topics are optional, hide at first
var inital = newsletter.is(":checked");
var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
var topicInputs = topics.find("input").attr("disabled", !inital);
// show when newsletter is checked
newsletter.click(function () {
topics[this.checked ? "removeClass" : "addClass"]("gray");
topicInputs.attr("disabled", !this.checked);
});
});
</script>

<style type="text/css">
#commentForm { width: 500px; }
#commentForm label { width: 250px; }
#commentForm label.error, #commentForm input.submit { margin-left: 253px; }
#signupForm { width: 670px; }
#signupForm label.error {
margin-left: 10px;
width: auto;
display: inline;
}
#newsletter_topics label.error {
display: none;
margin-left: 103px;
}
</style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<fieldset>
<legend>Validating a complete form</legend>
<%--<p>
<label for="firstname">Firstname</label>
<input id="firstname" name="firstname" type="text" />
</p>
<p>
<label for="lastname">Lastname</label>
<input id="lastname" name="lastname" type="text" />
</p>--%>
<p>
<label for="username">Username</label>
<input id="username" name="username" type="text" />
</p>
<p>
<label for="password">Password</label>
<input id="password" name="password" type="password" />
</p>
<p>
<label for="confirm_password">Confirm password</label>
<input id="confirm_password" name="confirm_password" type="password" />
</p>
<%--<p>
<label for="email">Email</label>
<input id="email" name="email" type="email" />
</p>--%>
<p>
<label for="agree">Please agree to our policy</label>
<input type="checkbox" class="checkbox" id="agree" name="agree" />
</p>
<p>
<label for="newsletter">I'd like to receive the newsletter</label>
<input type="checkbox" class="checkbox" id="newsletter" name="newsletter" />
</p>
<fieldset id="newsletter_topics">
<legend>Topics (select at least two) - note: would be hidden when newsletter isn't selected, but is visible here for the demo</legend>
<label for="topic_marketflash">
<input type="checkbox" id="topic_marketflash" value="marketflash" name="topic" />
Marketflash
</label>
<label for="topic_fuzz">
<input type="checkbox" id="topic_fuzz" value="fuzz" name="topic" />
Latest fuzz
</label>
<label for="topic_digester">
<input type="checkbox" id="topic_digester" value="digester" name="topic" />
Mailing list digester
</label>
<label for="topic" class="error">Please select at least two topics you'd like to receive.</label>
</fieldset>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
</fieldset>

<div id="signupPersonal">
<table>
<tr>
<td class="tdRight"><asp:Label ID="LabelName" runat="server" Text="Name:"></asp:Label></td>
<td class="tdLeft"><asp:TextBox name="firstname" ID="TextBoxName" runat="server" ClientIDMode="Static" MaxLength="50"></asp:TextBox></td>
</tr>
<tr>
<td class="tdRight"><asp:Label ID="LabelSurname" runat="server" Text="Surname:"></asp:Label></td>
<td class="tdLeft"><asp:TextBox class="required" ID="TextBoxSurname" runat="server" ClientIDMode="Static" MaxLength="50"></asp:TextBox></td>
</tr>
<tr>
<td class="tdRight"><asp:Label ID="LabelIDNumber" runat="server" Text="ID Number:"></asp:Label></td>
<td class="tdLeft"><asp:TextBox class="required digits" ID="TextBoxIDNumber" runat="server" ClientIDMode="Static" TextMode="SingleLine" MaxLength="20"></asp:TextBox></td>
</tr>
<tr>
<td class="tdRight"><asp:Label ID="LabelEmail" runat="server" Text="Email Address (to be used as username):"></asp:Label></td>
<td class="tdLeft"><asp:TextBox name="email" type="email" ID="TextBoxEmail" runat="server" ClientIDMode="Static" TextMode="SingleLine" MaxLength="50"></asp:TextBox></td>
</tr>
<tr>
<td class="tdRight"><asp:Label ID="LabelPassword" runat="server" Text="Password:"></asp:Label></td>
<td class="tdLeft"><asp:TextBox name="password" type="password" ID="TextBoxPassword" runat="server" ClientIDMode="Static" TextMode="Password" MaxLength="50"></asp:TextBox></td>
</tr>
<tr>
<td class="tdRight"><asp:Label ID="LabelConfirmPassword" runat="server" Text="Confirm Password:"></asp:Label></td>
<td class="tdLeft"><asp:TextBox name="confirm_password" type="password" ID="TextBoxConfirmPassword" runat="server" ClientIDMode="Static" TextMode="Password" MaxLength="50"></asp:TextBox></td>
</tr>

<tr><td colspan="2"><asp:Button CssClass="register" ID="ButtonRegister" runat="server" Text="Register" OnClick="ButtonConfirm_Click" class="submit" type="submit" /></td></tr>
</table>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="javascript" runat="server">

</asp:Content>


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>