ASP Form Field Validation Question

B

bravesplace

I have a form field on an ASP page and was wondering if I can require
the number that is entered to begin with a 0 or a 2. If the number
starts with anything else, the user is notified to update the number
correctly (Your [FormField] must begin with a 0 or a 2, Please update
your entry). Any code snip of this would be great.
 
B

Bob Barrows [MVP]

I have a form field on an ASP page and was wondering if I can require
the number that is entered to begin with a 0 or a 2. If the number
starts with anything else, the user is notified to update the number
correctly (Your [FormField] must begin with a 0 or a 2, Please update
your entry). Any code snip of this would be great.

Since this is an ASP group, I will provide an ASP answer:

<%
dim val, msg, visible
val=request.form("FormField")
if len(val) > 0 then
if left(val,1) = "0" or left(val,1) = "2" then
visible="none"
'process the data
else
msg="Your [FormField] must begin with a 0 or a 2, Please update" & _
" your entry"
visible="block"
end if
end if
%>
<html><body><form method="post">
Enter FormField: <input type="text" name="FormField"
value=" <%= server.htmlencode(val) %>">
<div style="display:<%=visible%>"><%=msg%></div>
<INPUT type="submit" value="Submit">
</form></BODY></HTML>

If you want a client-side answer, post to the
microsoft.public.scripting.jscript group.

HTH,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,144
Messages
2,570,823
Members
47,369
Latest member
FTMZ

Latest Threads

Top