当前位置:网站首页>JS regular verification time test() method

JS regular verification time test() method

2022-06-23 17:40:00 It workers

test() Method to detect whether a string matches a pattern .

The rules .test(str);

Return value : If the string contains text that matches the written regular , Then return to true, Otherwise return to false.

In the following example , We will search "W3School":

<script type="text/javascript">
var str = "Visit W3School";
var patt1 = new RegExp("W3School");

var result = patt1.test(str);

document.write("Result: " + result);
</script>

Output :

Result: true
原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201061849383451.html