JavaScript Test () method

Source: Internet
Author: User

JavaScript Test () method

JavaScript REGEXP Objects

Definition and usage

The test () method is used to detect whether a string matches a pattern.

Grammar
Regexpobject.test (String)
Parameters Description
String Necessary. The string to detect.
return value

Returns True if the string contains text that matches regexpobject, otherwise false.

Description

Call the test () method of the RegExp object R and pass the string s to it, which is equivalent to this expression: (R.exec (s)! = null).

Instance

In the following example, we will retrieve "W3school":

<script type= "Text/javascript" >var str = "Visit w3school"; var patt1 = new RegExp ("W3school"); var result = Patt1.test (str);d ocument.write ("Result:" + result);</script>

Output:

Result:true
Tiy
Test ()
How to use Test () to retrieve a string.

JavaScript Test () method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.