Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use test function in js regular expression

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use the test function in js regular expressions. It is very detailed and has a certain reference value. Friends who are interested must read it!

Function description: the return value of this method is a Boolean value, through which you can match whether the string exists in the regular expression matching result. If there is a match, return ture. If there is no match, return false. This method is often used to judge the validity of user input data, such as verifying the legitimacy of Email.

Basic syntax: objReg.test (objStr)

ObjReg required RegExp object name

The string to be matched by the objStr

Explain the example code:

/ * Designed By Androidyue*//* function: check the validity of the Email address * / function checkEmail () {/ / get the information var objStr=document.getElementById ("email") entered by the user in the text box. Value;// sets the regular expression var objReg=//w+ [@] {1} / w + [.] / xss_clean / [objStr) that matches Email. / / if you judge whether there is a match in the string, if there is a correct message, the error if (objReg.test (objStr)) {alert ("the Email address is legal!");} else {alert ("the Email address is illegal!");}} enter the Email address:

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report