How to use test in JavaScript

This article describe about test() Method in JavaScript.
  • 1671

test() Method in JavaScript

It is used to tests for matching in a string.

Return true if finds match, otherwise false.

Syntax

RegExpObject.test(string)

 

Parameter Description
string Required. String for search

Example

<!DOCTYPE html>

<html>

<body>

<script type="text/javascript">

    var str = "This is my first paragraph!";

    var pattern = /first/g;

    var res = pattern.test(str);

    document.write("Returned value: " + res);

    patt = /dotnetheaven.com/g;

    res = pattern.test(str);

    document.write("<br />Returned value: " + res);

</script>

</body>

</html>

 

Output

 

pic3.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.