...

View Full Version : How to validate the text box input?



superman2004
08-18-2004, 04:09 AM
i face a problem to validate the text box input.

Now i using the javascript to validate the input, but it using the alpha, alphanumeric, numeric........

<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("form");
frmvalidator.addValidation("cname","maxlen=30","The Max length for name is 30");
frmvalidator.addValidation("age","maxlen=3","The Max length for age is 3");
frmvalidator.addValidation("age","numeric");

frmvalidator.addValidation("gender","maxlen=10","The Max length for gender is 10");
frmvalidator.addValidation("gender","alpha");

frmvalidator.addValidation("race","maxlen=20","The Max length for race is 20");
frmvalidator.addValidation("race","alpha");

frmvalidator.addValidation("hobby","maxlen=50","The Max length for hobby is 50");
frmvalidator.addValidation("hobby","alpha");

frmvalidator.addValidation("interest","maxlen=50","The Max length for interest is 50");
frmvalidator.addValidation("interest","alpha");

frmvalidator.addValidation("occupation","maxlen=50","The Max length for occupation is 50");
frmvalidator.addValidation("occupation","alpha");

frmvalidator.addValidation("others","maxlen=500","The Max length for others is 500");

</script>

If i type in the ' then it will not insert into the database then how? i don't want to let user to input ' in the text box.

I'm using ASP, IIS, MS SQL Server 2000, Javascript

Morgoth
08-18-2004, 11:00 PM
Here you go!

Single Quotes give me a syntax error!
http://www.codingforums.com/showthread.php?t=9843

This is exactly what you problem is. If you wish to submit a ' as in "It's" then you need to change it to "It''s" so the database knows it's a string, and not part of the SQL command.

Don't worry, the double single quotes wont look like "It''s", it will change back when you write it to the screen.
This also goes for double quotes.
Example:


<%
Response.Write "It''s"
Response.Write "<br>"
Response.Write """Here"""
%>

Display:

It's
"Here"


Try it yourself!

That help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum