The test function in JavaScript

Source: Internet
Author: User

The test function method in JavaScript is to return a Boolean value that indicates whether there is a pattern in the string being looked up. How to use:

Rgexp.test (str)

Where Rgexp is a required option. A regular expression object that contains a regular expression pattern or an available flag.

STR is a required option. The string on which to test the lookup.

The test function method in JavaScript checks if there is a pattern in the string, returns True if it exists, or returns false. The properties of the global RegExp object are not modified by the test method.

The following example illustrates the use of the test function method in javascript: www.82676666.com

function Testdemo (Re, s) {

var S1; Declares a variable.

Checks whether the string has a regular expression.

if (Re.test (s))//test is present.

S1 = "contains"; s contains the pattern.

Else

S1 = "does not contain"; s does not contain a pattern.

Return ("'" + S + "'" + S1 + "'" + Re.source + "'"); Returns a string.

}

The test function in JavaScript

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.