//
// 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) {
if(username.length < 6 || username.length > 20){
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) {
let validLength = password.length >= 8 && password.length <= 30
let lower = /[a-z]/.test(password)
let upper = /[A-Z]/.test(password)
let number = /\d/.test(password)
if(!validLength || !lower || !upper || !number)
throw 'Password is not valid!';
/*
let number = false;
let lCase = false;
let uCase = false;
for(let i = 0; i < password.length; i++){
let char = password.charAt(i);
if(!!parseInt(char)){
number = true;
}else if(char == char.toLowerCase()){
lCase = true;
}else if(char == char.toUpperCase()){
uCase = true;
}
}
let valid = number && lCase && uCase;
if(password.length < 8 || password.length > 30 || !valid){
throw 'Password is not valid!';
} -->
*/
}
// 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.