Coder_Nick Coder_Nick - 2 years ago 91
Javascript Question

If/else syntax on password verification in javascript

I'm fairly new to javascript and trying to list out the characters missing from a failed password to tell users what they need to input.

window.onload = function()
var info = document.getElementById("info");

var test = document.getElementById("myForm").test;

test.onclick = function(e)
var pw = document.getElementById("myForm").pw.value;

var formula = /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{6,}/;

else if pw.match(/\d/g) == null {
info.innerHTML = "You need a number";

} else {

info.innerHTML = "You need a number."



The above is just a first run through of checking if the user inputted a password with now numbers. But I keep getting an

Uncaught SyntaxError: Unexpected identifier

in chrome dev tools with the pw.match portion underlined. I've looked elsewhere online and my syntax looks correct. Where am I going wrong?

Answer Source

You need parentheses around the condition of your if block.

 else if (pw.match(/\d/g) == null) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download