<Html>
Network reference document character operation functions
<script language="javascript">
Function calculate () {String. prototype. lenB = function () {return this. replace (/[^ \ x00-\ xff]/g ,"**"). length;} // var str = "This is a function that can calculate Chinese characters into two bytes"; var str = document. all. uInput. value alert ("Old algorithm =" + str. length); alert ("New Algorithm =" + str. lenB () ;}</script>
Enter <input name = "uInput" type = "text"> <input type = "button" value = "calculate" onclick = "calculate () "/> the result is <input name =" result "type =" text "> javascript/JS restricts that a user name can only enter Chinese characters, letters, and underscores. http://blog.163.com/peihu@126/blog/static/66003219201332554849288/ An example of user name verification: html: <input type = "text" value = "" name = "username" id = "username" onblur = "checkUser () "/> <span id =" usertips "> </span> js: function checkUser () {var username = $ (" # username "). val (); if (! Username. match (/^ [\ u4E00-\ u9FA5a-zA-Z0-9 _] {3,20} $/) {var msg = "Chinese English letters, numbers, underscores "; $ ("# usertips" ).html (msg) ;}else {$ ("# usertips" ).html ('');}} 1. Only numbers <input name = "username" type = "text" onkeyup = "value = this. value. replace (/\ D +/g, '')"> 2. Only English letters, numbers, and underscores (_) are allowed) <input name = "username" type = "text" style = "ime-mode: disabled "> <input name =" username "type =" text "onkeyup =" value = value. replace (/[^ \ W \. \/]/ig ,'') "> 3. Only English letters, numbers, and ==#< input name =" username "type =" text "onkeyup =" value = value. replace (/[^ \ w =@ #] | _/ig ,'') "> 4. Only Chinese characters <input name =" username "type =" text "onkeyup =" value = value. replace (/[^ \ u4E00-\ u9FA5]/g ,'') "> 1. Only numbers <input name =" username "type =" text "onkeyup =" value = this. value. replace (/\ D +/g, '')"> 2. Only English letters, numbers, and underscores (_) are allowed) <input name = "username" type = "text" style = "ime-mode: disable D "> <input name =" username "type =" text "onkeyup =" value = value. replace (/[^ \ w \. \/]/ig ,'') "> 3. Only English letters, numbers, and ==#< input name =" username "type =" text "onkeyup =" value = value. replace (/[^ \ w =@ #] | _/ig ,'') "> 4. Only Chinese characters <input name =" username "type =" text "onkeyup =" value = value. replace (/[^ \ u4E00-\ u9FA5]/g, '')"> only numbers can be entered: "^ [0-9] * $ ". Only n digits can be entered: "^ \ d {n} $ ". You can only enter at least n digits: "^ \ d {n,} $ ". Only m ~ can be input ~ N-digit :. "^ \ D {m, n }$" only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $ ". Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $ ". Only 1 ~ Positive number of three decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $ ". Only a non-zero positive integer can be entered: "^ \ +? [1-9] [0-9] * $ ". Only a non-zero negative integer can be entered: "^ \-[1-9] [] 0-9" * $. Only 3 characters can be entered: "^. {3} $ ". You can only enter A string consisting of 26 English letters: "^ [A-Za-z] + $ ". You can only enter a string consisting of 26 uppercase letters: "^ [A-Z] + $ ". You can only enter a string consisting of 26 lower-case English letters: "^ [a-z] + $ ". You can only enter a string consisting of a number and 26 English letters: "^ [A-Za-z0-9] + $ ". You can only enter a string consisting of digits, 26 English letters, or underscores (_): "^ \ w + $ ". Verify the User Password: "^ [a-zA-Z] \ w {5, 17} $". The correct format is: start with a letter, with a length of 6 ~ It can only contain characters, numbers, and underscores. Check whether ^ % & ',; =? $ \ "And other characters:" [^ % & ',; =? $ \ X22] + ". Only Chinese characters can be entered: "^ [\ u4e00-\ u9fa5] {0,} $"