Nov 8, 2018

JavaScript Regular expression Example

To check a string has at least 2 characters and begins with capital letter:

var str = "The best things in life are free";
var patt = new RegExp("^[A-Z]\\w+");
var res = patt.test(str);
alert(res);