467,081 Members | 968 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

ASP Form Field Validation Question

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.

Feb 14 '06 #1
  • viewed: 1194
Share:
2 Replies
br*********@yahoo.com wrote:
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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 14 '06 #2
Thank you so much for all your help.

Feb 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by CJM | last post: by
2 posts views Thread by Kostas | last post: by
9 posts views Thread by julie.siebel@gmail.com | last post: by
5 posts views Thread by lucyh3h@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.