//
// 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) {
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
function validatePassword(password) {
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);
wireup(elements.password, validatePassword);
function wireup(element, callback) {
element.addEventListener('input', function(e) {
try {
callback(element.value);
element.parentElement.classList.remove('error');
delete errors[element.id];
} catch (e) {
element.parentElement.classList.add('error');
errors[element.id] = e;
}
var fieldsInError = Object.keys(errors);
if(fieldsInError.length == 0){
elements.form.classList.remove('error');
} else {
errorMessage.innerText = fieldsInError.map(function(e){ return errors[e]; }).join('\r');
elements.form.classList.add('error');
}
});
}
})();
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.