Assignment 2 extra Practice Set Solution

Ajax, Bootstrap from - JavaScript

by Angela Baruth

HTML

<h2>
Ajax, Bootstrap from - JavaScript
</h2>

<form id="basicBootstrapForm" class="form-horizontal">
    <div class="form-group">

        <label class="col-xs-3 control-label">Full name</label>
        <div class="col-xs-4">
            <input type="text" class="form-control" name="firstName" placeholder="First name" />
        </div>
        <div class="col-xs-4">
            <input type="text" class="form-control" name="lastName" placeholder="Last name" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-xs-3 control-label">Username</label>
        <div class="col-xs-5">
            <input type="text" class="form-control" name="username" /> 6 and less than 30 characters long and only consist of alphabetical, number
        </div>
    </div>

    <div class="form-group">
        <label class="col-xs-3 control-label">Email address</label>
        <div class="col-xs-5">
            <input type="text" class="form-control" name="email" />
        </div>
    </div>
		
    <div class="form-group">
        <label class="col-xs-3 control-label">Password</label> 
        <div class="col-xs-5">
            <input type="password" class="form-control" name="password" /> cannot be the same as username with required  
        </div> 
    </div>

    <div class="form-group">
        <label class="col-xs-3 control-label">Gender</label>
        <div class="col-xs-6">
            <div class="radio">
                <label>
                    <input type="radio" name="gender" value="male" /> Male
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" name="gender" value="female" /> Female
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" name="gender" value="other" /> Other
                </label>
            </div>
        </div>
    </div>

    <div class="form-group">
  ...

JavaScript

/* CSCI E-3 Introduction to Web Programming Using Javascript
 * Fall 2016
 *
 * 2. Assignments Practice Set extra
 *
 */
"use strict";

/* Ajax, Bootstrap from - JavaScript - Assignment 2 extra */

$(document).ready(function() {
    // Generate a simple captcha 9+179= should 188
    function randomNumber(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    }
    $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));

    $('#basicBootstrapForm').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
		
		/* name (first and last name with required */
        fields: {
            firstName: {
                row: '.col-xs-4',
                validators: {
                    notEmpty: {
                        message: 'The first name is required'
                    }
                }
            },
            lastName: {
                row: '.col-xs-4',
                validators: {
                    notEmpty: {
                        message: 'The last name is required'
                    }
                }
            },
			
			/*  username (must be more than 6 and less than 30 characters long and  only consist of alphabetical, number, dot and underscore with required */
            username: {
                validators: {
                    notEmpty: {
                        message: 'The username is required'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The username must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: 'The username can only consist of...