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