RegExp Pattern Matching +location page Jump +cookie/localstorage Local Storage

Source: Internet
Author: User

In the process of learning JS, according to the knowledge points to write some code to test, in order to verify.

This procedure uses the following knowledge points:

1.regexp, pattern matching of data

2. Use the Location object for page jumps.

Use of local storage such as 3.cookie/localstorage

<! DOCTYPE html> for= "Inp1" id= "Label1" >User name:<input id= "INP1" type= "text" placeholder= "username" ></label><br/><label for= "Inp2" id= "Label2" >Password:<input id= "inp2" type= "password" placeholder= "password" ></label><br/><button id= "btn1" onclick = "JData ()" >submit</button><script type= "Text/javascript" >varSpan1=document.getelementbyid ("Span1"); varInp1=document.getelementbyid ("Inp1"); varInp2=document.getelementbyid ("Inp2"); functionJData (ID) {//Verify user name: Only 1-30 strings beginning with a letter can be entered        varpatt1=NewREGEXP (/^[a-z][a-za-z0-9_-]{0,29}/, "G"); //Check Password: Only 6-20 letters, numbers, underscores can be entered        varPatt2=NewREGEXP (/[a-za-z0-9_]{6,20}/, "G"); varRes=patt1.test (Inp1.value) &&patt2.test (Inp2.value); if(res) {//window.location.href= "http://www.baidu.com";Window.location.assign ("http://www.baidu.com");//Window.event.returnValue = false;}Else{span1.innerhtml= "Username or password wrong"; }    }</script></body>

1.regexp notes

A.[] and meta data

1) [character] understood as the opposite bracket specific content matches

2)., \w, \d, understood to be a kind of a wildcard

B. quantifiers

n+; at least once/once and above

N. Any time

N?;0 Times or 1 times

n{}; This specified number of times: n{x};x Times

N{x,y} times can be between x~y

N{x,} at least x times × times and above


^n; start with n

n$; end With N

RegExp Pattern Matching +location page Jump +cookie/localstorage Local Storage

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.