Results 1 to 5 of 5

Thread: Form Validation

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Form Validation

    Are there any free frameworks or apis or pre-built javascript files that I can easily plug in for form validation?

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Form Validation

    There is one here:
    http://www.javascript-coder.com/html...lidation.phtml

    Which is easy to use. The problem is this is not W3C compliant, so your page won't validate. I am currently working on something similar which is W3C compliant.
    Chris

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Form Validation

    You could just write your own, it won't be as heavy as a 'prepared' one.

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Form Validation

    I am almost finished with an object oriented javascript form validation, similar to the one above.

    The size of the script include is less than the average jpeg image.

    If you just want a quick script to check required fields then something like this will do:

    Code:
    function validate()
    {
    	var output = true;
    	var msg = "Please correct the following errors:\n";
    	
    	if(document.forms["contact_us"].name.value.length < 3) { output = false; msg += "\n - Name is missing or too short."; }
    	if(document.forms["contact_us"].email.value.length < 5) { output = false; msg += "\n - Email address is missing or too short."; }
    	
    	if(!output)
    	{
    		alert(msg);
    		return false;
    	}
    	else
    	{
    		return true;
    	}
    }
    And the HTML form:

    Code:
    <form action='somewhere.html' name='contact_us' method='post' onsubmit='return validate()'>
    
    Name: <input type='text' name='name' />
    Email: <input type='text' name='email' />
    <input type='submit' name='form_submit' />
    
    </form>
    Note the onsubmit event in the <form> tag. This tells the form to call the validate function when submitted, the validate function returns true/false. If false the form will not be submitted, and a message will popup with the errors.
    Chris

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Form Validation

    Just added this to the Codebank: Easy form validation - http://www.vbforums.com/showthread.php?p=3380227
    Chris

Posting Permissions

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



Click Here to Expand Forum to Full Width