Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

registration form validation 1

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
I need help with my registration form. It was working fine until I added a RegularExpressionValidator. Now it seems I can enter whatever I want in any field I want, and the form submits without error. Even If I take out the RegularExpressionValidator none of the other code is working now. It just submits the form without error, no matter what bad info I enter.

Can someone help me debut this code?

Here's the form code:

<form runat=&quot;server&quot; name=&quot;register&quot;>
<div align=&quot;left&quot;> </div>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr valign=&quot;top&quot;>
<td width=&quot;27%&quot; class=&quot;body&quot;>Username:</td>
<td width=&quot;73%&quot; class=&quot;body&quot;><asp:TextBox id=&quot;MAJOR_KEY&quot; runat=&quot;server&quot;></asp:TextBox></td>
</tr>
<tr valign=&quot;top&quot;>
<td class=&quot;body&quot;><br>
Choose a Password:</td>
<td class=&quot;body&quot;><br> <asp:TextBox id=&quot;PASSWORD&quot; runat=&quot;server&quot; TextMode=&quot;Password&quot;></asp:TextBox> <asp:RequiredFieldValidator id=&quot;PASSWORDReqVal&quot; runat=&quot;server&quot; Display=&quot;Dynamic&quot; ErrorMessage=&quot;Password. &quot; ControlToValidate=&quot;PASSWORD&quot; Font-Size=&quot;12&quot; Font-Name=&quot;Verdana&quot;>
*</asp:RequiredFieldValidator></td>
</tr>
<tr valign=&quot;top&quot;>
<td class=&quot;body&quot;>Confirm Password:</td>
<td class=&quot;body&quot;><asp:TextBox id=&quot;PASSWORD2&quot; runat=&quot;server&quot; TextMode=&quot;Password&quot;></asp:TextBox> <asp:RequiredFieldValidator id=&quot;PASSWORD2ReqVal&quot; runat=&quot;server&quot; Display=&quot;Dynamic&quot; ErrorMessage=&quot;Re-enter Password. &quot; ControlToValidate=&quot;PASSWORD2&quot; Font-Size=&quot;12&quot; Font-Name=&quot;Verdana&quot;>
*</asp:RequiredFieldValidator> <asp:CompareValidator id=&quot;CompareValidatorPASSWORD2&quot; runat=&quot;server&quot; Display=&quot;Static&quot; ErrorMessage=&quot;Re-enter Password. &quot; ControlToValidate=&quot;PASSWORD2&quot; Font-Size=&quot;11&quot; Font-Name=&quot;Arial&quot; ControlToCompare=&quot;PASSWORD&quot;>
Password fields don't match</asp:CompareValidator> </td>
</tr>
onSubmit=&quot;return validatePwd()&quot;
<tr valign=&quot;top&quot;>
<td class=&quot;body&quot;><br>
Enter your Email address:</td>
<td class=&quot;body&quot;><br> <asp:TextBox id=&quot;EMAIL&quot; runat=&quot;server&quot;></asp:TextBox> <asp:RequiredFieldValidator id=&quot;EMAILReqVal&quot; runat=&quot;server&quot; Display=&quot;Dynamic&quot; ErrorMessage=&quot;Email. &quot; ControlToValidate=&quot;EMAIL&quot; Font-Size=&quot;12&quot; Font-Name=&quot;Verdana&quot;>*</asp:RequiredFieldValidator> <asp:RegularExpressionValidator id=&quot;EMAILRegexVal&quot; runat=&quot;server&quot; Display=&quot;Static&quot; ErrorMessage=&quot;Email. &quot; ControlToValidate=&quot;EMAIL&quot; Font-Size=&quot;11&quot; Font-Name=&quot;Arial&quot; ValidationExpression=&quot;^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$&quot;>Not a valid e-mail address. Must follow email@host.domain</asp:RegularExpressionValidator></td>
</tr>
<tr valign=&quot;top&quot;>
<td class=&quot;body&quot;>Confirm Email address:</td>
<td class=&quot;body&quot;><asp:TextBox id=&quot;EMAIL2&quot; runat=&quot;server&quot;></asp:TextBox> <asp:RequiredFieldValidator id=&quot;EMAIL2ReqVal&quot; runat=&quot;server&quot; Display=&quot;Dynamic&quot; ErrorMessage=&quot;Re-enter Password. &quot; ControlToValidate=&quot;EMAIL2&quot; Font-Size=&quot;12&quot; Font-Name=&quot;Verdana&quot;>*</asp:RequiredFieldValidator> <asp:CompareValidator id=&quot;CompareValidatorEMAIL2&quot; runat=&quot;server&quot; Display=&quot;Static&quot; ErrorMessage=&quot;Re-enter Password. &quot; ControlToValidate=&quot;EMAIL2&quot; Font-Size=&quot;11&quot; Font-Name=&quot;Arial&quot; ControlToCompare=&quot;EMAIL&quot;>Email fields don't match.</asp:CompareValidator></td>
</tr>
<tr valign=&quot;top&quot;>
<td>&nbsp;</td>
<td><asp:Button id=&quot;Button1&quot; onclick=&quot;Button1_Click&quot; runat=&quot;server&quot; Text=&quot;Register&quot;></asp:Button></td>
</tr>
</table>
</form>
 
Joulius,

It still doesn't work correctly after moving the form tags.

I've been reading about the Button's Click method, and that you must still test Page.IsValid before executing any code to save. It looks like validation doesn't stop your events from executing. And you handle that with isValid.

Any experience with isValid, or how I might use it on this form.

As for not using <asp:table>, I've always figured that if you use the asp controls, then the server has to process them, whereas a standard <table> tag would be processed by the browser. Just trying to keep things simple, and not over-burden the server with things the client can handle. Am I mis-guided in this belief?
 
Got it!

Putting a conditional page.IsValid inside the button1_click method solved the problem.

<script runat=&quot;server&quot;>
Sub Button1_Click(sender As Object,e As EventArgs)
If Page.IsValid Then

'...page code here

End If
End Sub
</script>

Thanks for all of your help Joulius!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top