MENU
Prototype Methods
RegExp.prototype.exec()
Executes a search for a match in its string parameter. It is the reverse of String.prototype.match().
RegExp.prototype.test()
Tests for a match in its string parameter.
RegExp.prototype.toString()
Returns a string representing the specified object. Overrides the Object.prototype.toString() method.
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var r = /a/gi;
console.log(r.exec("123abcABC")); // ["a", index: 3, input: "123abcABC"]
console.log(r.test("123abcABC")); // true
console.log(r.toString()); // /a/gi
</script></body><html>
This standard function allows you to retrieve the query strings in a URL.
RESETRUNFULL
<!DOCTYPE html><html><body><script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex=new RegExp(
"[?&]"+name+"(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));}var foo = getParameterByName('foo');
</script></body><html>
The following standard function validates an email address.
RESETRUNFULL
<!DOCTYPE html><html><body><script>
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);}
</script></body><html>