//
// Complete implementations of the validateUsername and validatePassword functions
// throwing errors when invalid. You may use: https://developer.mozilla.org if you need help with syntax
// https://getfirebug.com/firebug-lite-debug.js as external resource for a build-in console window
// A valid username is at least 6 characters long
// A valid username cannot be longer than 20 characters
function validateUsername(username) {
//Split username into an array.
//check length of username of array
//compare to boundries
var withInRange = checkLengths(username, 6, 20);
if (!withInRange) {
throw 'Username is not valid!';
}
}
// A Valid password must be at least 8 characters long
// A Valid password cannot be longer than 30 characters
// A valid password must contain at least 1 number
// A valid password must contain at least 1 UPPER case letter and 1 lower case letter
function validatePassword(password) {
var passwordArr = password.split('');
var passLength = passwordArr.length;
var withInLength = checkLengths(password, 8, 30);
var containsNumber = false;
var isLower = false;
var isUpper = false;
passwordArr.forEach(char => {
if (/[0-9]/g.test(char)) {
containsNumber = true;
} else if(/[a-z]/g.test(char)) {
isLower = true;
} else if(/[A-Z]/g.test(char)){
isUpper = true;
}
});
if (!withInLength || !containsNumber || !isLower || !isUpper) {
throw 'Password is not valid!';
}
}
function checkLengths(str,len1, len2){
if(str.length < len1 || str.length > len2){
return false;
}
return true;
}
// You can ignore everything below this comment
(function() {
var elements = {
username: document.getElementById('inputUsername'),
password: document.getElementById('inputPassword'),
errorMessage: document.getElementById('errorMessage'),
form: document.getElementsByClassName('ui form')[0]
};
var errors = {};
wireup(elements.username, validateUsername);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.