Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to validate the text box input?

    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........
    Code:
    <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

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Here you go!

    Single Quotes give me a syntax error!
    Single Quotes give me a syntax error!

    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:
    Code:
    <%
    Response.Write "It''s"
    Response.Write "<br>"
    Response.Write """Here"""
    %>
    Display:
    It's
    "Here"
    Try it yourself!

    That help?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •