Javascript Regular Expression

In javascript, we can use regular expression to test if a given string contain the numbers, alphabet, or special characters. for example,

var re1 = /(?=.*\d)/;

var re1a = /(?=.*[a-z])/;

var re1b = /(?=.*[A-Z])/;

var re1c = /.{8,20}/;

var re2 = /(?=.*[*!@#\$%\^&])/;

console.log(“test numeric:” + re1.test(str));

console.log(“test lowercase:” + re1a.test(str));

console.log(“test upper:” + re1b.test(str));

console.log(“test if string between 8 – 20 character:” + re1c.test(str));

console.log(“test if string contain special characters:” + re2.test(str));