WordPress.org

Forums

Visual Form Builder
[resolved] Digit validation (7 posts)

  1. conflit-rgp
    Member
    Posted 2 years ago #

    Could you help me figuring out something? Is there a way to set a specified number or characters needed to validate the number field when specifying to validate digits?

    I want to use the "Number" field to collect ZIP codes validating for digits. But the "Number" field doesn't have a limit for number of characters to check against. It will validate anything as as long as it is a digit.

    Would that be a rule I write in the my-js.js file? If so how?

    http://wordpress.org/extend/plugins/visual-form-builder/

  2. Matthew Muro
    Visual Form Builder Pro
    Plugin Author

    Posted 2 years ago #

    Yes, you'd need to add a custom rule for that.

    http://docs.jquery.com/Plugins/Validation/#List_of_built-in_Validation_methods

    If you want to require a specific number of characters, you'd want to use minlength and maxlength.

  3. conflit-rgp
    Member
    Posted 2 years ago #

    jQuery(document).ready(function($) {
    $("#vfb-zip-code-95").validate({
    rules: {
    field: {
    required: true,
    minlength: 5,
    maxlength: 5
    }
    }
    });

    Here is the snippet I wrote out for the "Zip Code field on this page: http://www.styletrader.biz/signup/

    It still wont validate a min or max length of characters. I need your help haha.

  4. Matthew Muro
    Visual Form Builder Pro
    Plugin Author

    Posted 2 years ago #

    You are close.

    $("#newsletter-sign-up").validate({
    	rules: {
    		'vfb-zip-code-95': {
    			required: true,
    			minlength: 5,
    			maxlength: 5
    		}
    	}
    });
  5. conflit-rgp
    Member
    Posted 2 years ago #

    jQuery(document).ready(function($) {
        $.datepicker.setDefaults({
            dateFormat: 'mm-dd-yy',
            numberOfMonths: 1,
    		changeMonth: true,
    		changeYear: true,
    		yearRange: "c-90:c+1"
        });
    });

    This is a piece of code I already had in place in the "my-js.js file.

    I feel really dumb asking this, but how do I add this:

    $("#newsletter-sign-up").validate({
    	rules: {
    		'vfb-zip-code-95': {
    			required: true,
    			minlength: 5,
    			maxlength: 5
    		}
    	}
    });

    to what I currently have?

  6. Matthew Muro
    Visual Form Builder Pro
    Plugin Author

    Posted 2 years ago #

    jQuery(document).ready(function($) {
        $.datepicker.setDefaults({
            dateFormat: 'mm-dd-yy',
            numberOfMonths: 1,
    		changeMonth: true,
    		changeYear: true,
    		yearRange: "c-90:c+1"
        });
    
        $("#newsletter-sign-up").validate({
    	rules: {
    		'vfb-zip-code-95': {
    			required: true,
    			minlength: 5,
    			maxlength: 5
    		}
    	}
        });
    });
  7. conflit-rgp
    Member
    Posted 2 years ago #

    Thanks Matt! That did the trick.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic