View Full Version : Form Validation
Hatch
07-15-2002, 07:37 PM
Can someone point me in the right direction or (example) for form validation. I have a text box field in a form that connects to an access database. I want to check for numeric numbers only, and also if the record is not found to display a recond not found page instead of
Error Type:
ADODB.Field (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
Thanks
oracleguy
07-15-2002, 08:10 PM
Run this asp code to check for numaric numbers.
Dim xC, vC, zC
zC=ControlToValidate
vC = "1234567890"
For xC = 1 To Len(zC)
If Instr(vC, Mid(zC, xC, 1)) < 1 Then
'Error!
Exit For
End If
Next
oracleguy
07-15-2002, 08:12 PM
Then for the database part:
'Run your query first
If rs.EOF or rs.BOF then Response.Redirect("NotFound.aspx")
Change 'rs' to whatever your recordset control name is.
Hatch
07-15-2002, 08:58 PM
PERCECT!!
Thanks :thumbsup:
Morgoth
07-16-2002, 07:33 PM
Am I a newbie for asking this?
What are "numaric numbers"?
oracleguy
07-16-2002, 07:41 PM
I think he ment numaric characters/integers.
Morgoth
07-16-2002, 07:44 PM
Ah...
and that is?
whammy
07-17-2002, 02:22 AM
0-9.
Morgoth, please limit your posts in this forum to questions about ASP or attempting to help someone with their ASP problem.
Understood?
Morgoth
07-17-2002, 07:36 AM
Ok Whammy, but alot of this is new to me, and i want to suck up all the info I can so my code and applications will be perfect or close to being that way.
whammy
07-17-2002, 02:18 PM
Sorry if I was mistaken, it seemed to me you were being a smart aleck. ;)
Anyway, he apparently wanted to limit the entry to digits - FYI here's another neat way to strip everything but numbers from a string using javascript with asp:
<script language="javascript" runat="server">
function ExtractNumbers(MixedString){
if(MixedString){
MixedString = MixedString.replace(/\D/g,'');
return MixedString;
}
}
</script>
You'd call that function just like a VBScript function. So, in addition to the way Oracleguy showed above, you could also see if something extracted from a database was only numeric like:
<%
If myString <> ExtractNumbers(myString) Then
'It's not numeric!
End If
%>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.