Duncan Wither

Home Notes Github LinkedIn

JS Cheatsheet

if Statements

if (true){
  console.log("Yay")
} else {
  console.log("Nay")
}

Regex

Courtesy of stack exchange ofc

var term = "sample1";
var re = new RegExp("^([a-z0-9]{5,})$");
if (re.test(term)) {
    console.log("Valid");
} else {
    console.log("Invalid");
}

Remember to escape all of your back slashes (i.e. to match a digit use \\d ).

Positive Integer Input

This is more html but here’s how to have an input field with only positive numbers (courtesy of [this link])