Tag:javascript

  • JavaScript regular modifier

    Time:2021-8-1

    In fact, there is also a very important modifier, which is rarely mentioned in the articles found on the Internet. It is m. In regular JavaScript, after ^ matches the newline character by default and before $matches the newline character by default, use / ^. + $/ so that only one line can be matched. […]

  • JavaScript regexp object (regular expression)

    Time:2021-7-28

    Use the explicit constructor of regexp. The syntax is: new regexp (“pattern” [, “flags”]).Use the implicit constructor of regexp in plain text format: / pattern / [flags].The pattern part is the regular expression pattern text to be used, which is required. In the first method, the pattern part exists as a JavaScript string and needs […]

  • Use JavaScript regular expressions marked with “g” correctly

    Time:2021-7-26

    Let’s talk about the use of regular expressions marked with “g”. First, let’s look at a piece of code, which is easier to understand from an example. Copy codeThe code is as follows: 1 function a(val) 2 { 3 var re = /^\d+$/g; 4 alert(re.lastIndex); 5 return re.test(val); 6 } 7 alert(a(5)); 8 alert(a(6)); Running […]

  • Summary of JavaScript regular expression usage

    Time:2021-7-23

    JavaScript regular expression usage: Copy codeThe code is as follows: function checkreg(myreg,mytext) { if(myreg.test(mytext) { alert(“ok”); return true; } else { return false; } } //Another way of writing Copy codeThe code is as follows: function checkreg(myreg,mytext) { var pattern = myreg; // Or var pattern = new regexp (myreg, “GI”);if(pattern.test(mytext)) { alert(“ok”); } } […]

  • JavaScript form validation regular expression encyclopedia [recommended]

    Time:2021-7-4

    For the specific use method combined with function, please also see the example code of JavaScript using regular expression for form verification in the next article Copy codeThe code is as follows: Regular expression matching Chinese characters: [u4e00-u9fa5]Commentary: matching Chinese is really a headache, with this expression is easy to do Matching double byte characters […]

  • JavaScript uses regular expressions for form validation sample code

    Time:2021-7-3

    JavaScript form validation regular expression EncyclopediaUsing regular expression to judge whether it is Arabic numerals of 0-9 Copy codeThe code is as follows: function regIsDigit(fData) { var reg = new RegExp(“^[0-9]$”); return (reg.test(fData)); } Use this expression to get the length of the string Copy codeThe code is as follows: function regDataLength(fData) { var valLength […]

  • JavaScript implementation of basic regular expressions

    Time:2021-6-25

    JavaScript supports regular expressions through regexp classes. For example: Copy codeThe code is as follows: var regApple = new RegExp(“apple”); It can match the first “apple” string in a string and is case sensitive. Add the second parameter “g” in the construction method to search all “apples” in the string, where “g” stands for “global”. […]

  • Proficient in regular expressions in JavaScript

    Time:2021-6-8

    Regular expressions can:· test a pattern of a string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. This is called data validationReplace the text. You can use a regular expression in the document to identify specific text, […]

  • Properties, methods and applications of JavaScript regexp object

    Time:2021-6-2

    JavaScript provides a regexp object to complete the operation and function of regular expressions. Each regular expression pattern corresponds to a regexp instance. There are two ways to create instances of regexp objects. Use the explicit constructor of regexp with the syntax: new regexp (“pattern” [, “flags”]).The implicit constructor of regexp is used, and the […]

  • Analysis of BOM principle and common usage examples of JavaScript browser object model

    Time:2021-6-2

    This paper introduces the principle and common usage of object model BOM in JavaScript browser. The details are as follows: What is bom BOM: Browser Object Model It can also be seen from the figure above: Window object is the top (core) object of BOMAll objects are extended through it, which can also be called […]

  • Regexp property, method and application analysis of JavaScript regular expression

    Time:2021-5-13

    Use the explicit constructor of regexp with the syntax: new regexp (“pattern” [, “flags”]).The implicit constructor of regexp is used, and the plain text format is adopted: pattern / [flags].The pattern section is the regular expression pattern text to be used and is required. In the first way, the pattern part is in the form […]

  • JavaScript mobile phone number regular expression verification function

    Time:2021-5-12

    Copy codeThe code is as follows: function checkMobile(){     var sMobile = document.mobileform.mobile.value     if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){          Alert (“not the complete 11 digit mobile phone number or the top seven digits of the correct mobile phone number”);        document.mobileform.mobile.focus();         return false;     } } The following is a simple analysis of the regular expression above by developer editor. With the increase […]