In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use the test () statement in JavaScript". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the test () sentence in JavaScript".
In JavaScript, the function of the test () method is to test whether the string matches the regular expression, the syntax "RegExpObject.test (string)", the match returns true, and the mismatch returns false.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
JavaScript string is the most frequently used data type in programming, and it is necessary to operate on a string in many places, such as judging whether a string is a legal E-mail address, intercepting a specified part from a string, and so on.
Regular expression is a kind of logical formula used to match strings or special characters. the so-called logical formula is composed of some specific characters to represent some rules of special strings, which can express the filtering logic of string data.
The test () method in JavaScript tests whether the string matches the regular expression, returns true if it matches, and returns false if it doesn't match.
Syntax:
RegExpObject.test (string)
String is required. The string to detect.
Example:
Var str = "Hello World!"; var reg = / [amurg] / g; [xss_clean] (reg.test (str) + "
"); / / output: true
Description:
Call the test () method of the RegExp object r and pass it the string s, which is equivalent to this expression: (r.exec (s)! = null).
Example:
Var str= "Hello world!"; / look for "Hello" var patt=/Hello/g;var result=patt.test (str); [xss_clean] ("Returned value:" + result); / / look for "world" patt=/world/g;result=patt.test (str); [xss_clean] ("
Returned value: "+ result); / / look for" php "patt=/php/g;result=patt.test (str); [xss_clean] ("
Returned value: "+ result); thank you for reading. The above is the content of" how to use the test () sentence in JavaScript ". After the study of this article, I believe you have a deeper understanding of how to use the test () statement in JavaScript. The specific use of the situation also needs to be verified by practice. Here, the editor will push more articles on related knowledge points, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.