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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript validation

    I'm doing a project for school (GCSE) and i need some primary sources about the effectiveness of JavaScript validation (for a html form). So could you please answer this with information about how effective javascript validation is at reducing the number of errors made in imput, comparing it to other methods etc.

    Thanks

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Quote Originally Posted by Tristan.S-H View Post
    I'm doing a project for school (GCSE) and i need some primary sources about the effectiveness of JavaScript validation (for a html form). So could you please answer this with information about how effective javascript validation is at reducing the number of errors made in imput, comparing it to other methods etc.

    Thanks
    What does "other methods" mean?

    JavaScript form validation only provides convenience for users, not security. This means that JavaScript should be used as an "enhancement", not as a requirement. So your form should not be dependent on JavaScript alone to perform your validation. Instead, whatever server-side language you use to process the form (PERL, ASP, PHP, etc.) should also perform the same validation. Otherwise, people will be able to bypass your validation (and even possibly inject malicious code) simply by disabling Javascript.

    How effective the validation is depends on, er, the validation script. For example, form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation.

    Javascript can correct certain common errors - for example, strip inappropriate characters such as numbers in proper names, capitalise proper names (philip > Philip), format a postcode (ab73ds > AB7 3DS) or telephone number properly. But of course nothing can correct entries which are simply wrong.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 06-30-2013 at 10:57 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,455
    Thanks
    0
    Thanked 632 Times in 622 Posts
    In most cases the JavaScript validation can simply duplicate the server side validation - and so report immediately where there is an error in the input rather than waiting until the entire form has been filled out and submitted.

    Where an error will rarely occur and the code to test for it is long and complicated then that test can be omitted from the JavaScript and left for the server side validation to catch that error.

    There is nothing that the JavaScript validation can do that should not be duplicated oin the server side validation. The server side validation provides the security for the site owner while the JavaScript validation provides quick convenient responses for the person filling out the form.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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