reub77
01-11-2006, 10:45 PM
I usually work in PHP and in the past have never needed to validate radio buttons. Well now I need to do it in ASP. I have found some code for all the other validation. The trick is applying the radio button validation into the code. I'll put up some snippets of the code to give you an idea of what I'm trying to do:
<%
Function ValidateField(sFieldValue, sFieldType)
Dim bFieldIsOkay
' defaut it to true
bFieldIsOkay = True
' go to the field name to validate the entry
Select Case LCase(sFieldType)
Case "name"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "email"
If Len(sFieldValue) < 5 Then
bFieldIsOkay = False
Else
If Instr(1, sFieldValue, " ") <> 0 Then
bFieldIsOkay = False
Else
If InStr(1, sFieldValue, "@") < 2 Then
bFieldIsOkay = False
Else
If InStrRev(sFieldValue, ".") < InStr(1, sFieldValue, "@") + 2 Then
bFieldIsOkay = False
End If
End If
End If
End If
Case "homephone"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "new1"
If Len(sFieldValue) <> "checked" Then bFieldIsOkay = False
End Select
ValidateField = bFieldIsOkay
End Function
%>
And here is my form:
<form method="POST" NAME="TheForm" action="<%= Request.ServerVariables("Script_Name") %>">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bodytext">
<tr>
<td width="45%">*Are you new to the Heartland Veterinary Clinic? </td>
<td width="35%">
<!--new1-->
<input name="new1" type="radio" value="yes" <%= Request.Form("new1") %>>Yes
<input name="new1" type="radio" value="no" <%= Request.Form("new1") %>>No
</form>
This is just a snippet and so there's a lot of stuff missing. I've taken out the submit buttons in case you are wondering (my code has them). Please help me to know how to add validation for the "new1" radio buttons.
Thanks,
Reuben
<%
Function ValidateField(sFieldValue, sFieldType)
Dim bFieldIsOkay
' defaut it to true
bFieldIsOkay = True
' go to the field name to validate the entry
Select Case LCase(sFieldType)
Case "name"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "email"
If Len(sFieldValue) < 5 Then
bFieldIsOkay = False
Else
If Instr(1, sFieldValue, " ") <> 0 Then
bFieldIsOkay = False
Else
If InStr(1, sFieldValue, "@") < 2 Then
bFieldIsOkay = False
Else
If InStrRev(sFieldValue, ".") < InStr(1, sFieldValue, "@") + 2 Then
bFieldIsOkay = False
End If
End If
End If
End If
Case "homephone"
If Len(sFieldValue) = 0 Then bFieldIsOkay = False
Case "new1"
If Len(sFieldValue) <> "checked" Then bFieldIsOkay = False
End Select
ValidateField = bFieldIsOkay
End Function
%>
And here is my form:
<form method="POST" NAME="TheForm" action="<%= Request.ServerVariables("Script_Name") %>">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bodytext">
<tr>
<td width="45%">*Are you new to the Heartland Veterinary Clinic? </td>
<td width="35%">
<!--new1-->
<input name="new1" type="radio" value="yes" <%= Request.Form("new1") %>>Yes
<input name="new1" type="radio" value="no" <%= Request.Form("new1") %>>No
</form>
This is just a snippet and so there's a lot of stuff missing. I've taken out the submit buttons in case you are wondering (my code has them). Please help me to know how to add validation for the "new1" radio buttons.
Thanks,
Reuben