The composition principle of QQ numbers is very simple. One is that the length is at least five characters, and the maximum length is 2300000000 characters so far. This is the information provided by the QQ official website, below I will summarize some common examples of Regular Expression for QQ numbers. If you need them, please refer to them.
The QQ official code for verifying the QQ number is the best.
The Code is as follows: |
Copy code |
<Html> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/> <Title> check if the QQ format is correct in JS. </title> </Head> <Body> <Script type = "text/javascript"> <! -- Function $ (id ){ Return document. getElementById (id ); } Function checkQQ (qq ){ // Qq = qq. replace (/(^ s *) | (s * $)/g ,""); Var patrn =/^ [1-9] d {4, 9} $ /; If (patrn.exe c (qq )){ Qq = parseInt (qq, 10 ); If (qq> 10000 & qq <2300000000 ){ Return true; } } Return false; } Function check (){ Var qq =$ ('qq'). value; If (checkQQ (qq )){ Alert ('qq format is correct '); } Else { Alert ('incorrect qq format '); } } // --> </Script> <Input type = "text" id = "qq"/> <Input type = "button" onclick = "check ()" value = "query"/> </Body> </Html> |
Example 2
Pure QQ number
The Code is as follows: |
Copy code |
<Script language = "javascript"> Function checkfrom (){ Var num = document. getElementById ("text"). value; Regex =/^ [1-9] d {5, 8} $ /; If (! Regex. test (num )) { Alert ("enter the correct QQ number ") } Else { Alert ("correct "); } } </Script> <Input type = "text" id = "text" name = "text"> <Input type = "Submit" id = "Submit" name = "submit" value = "check" onclick = "checkfrom ();"> |
Example 3
This automatic forced dialog is based on the QQ number entered by the user
The Code is as follows: |
Copy code |
<Script> Function doload (){ Window. resizeTo (400,300 ); } Function turnToURL (){ Var ele = form1.qq; Var re = new RegExp ('^ [0-9] {4, 12}', "I "); Var url = 'HTTP: // wpa.qq.com/msgrd? V = 1 & Uin = '; If (ele. value. match (re) = null ){ Alert ('qq No. Is a digit [4--12. Enter again! '); Ele. focus (); Return; } Url = url + ele. value; Url = url + '& Site = ioshenmue & Menu = yes '; Window. location. href = url; } </Script> </Head> <Body onload = "doload ();"> <Form name = "form1" action = "" method = "post" onsubmit = "turnToURL ();"> <Input name = "qq" type = "text" id = "qq"/> <Label> <Input type = "submit" name = "button" id = "button" value = "submit"/> </Label> </Form> |