Validate text input fields in the form
<Script language = "JavaScript"> <br/> // determines whether it is an English letter <br/> function isenglish (name) {<br/> If (0 = Name. length) {<br/> return false; <br/>}< br/> for (I = 0; I <name. length; I ++) {<br/> If (65> name. charcodeat (I) | 128 <name. charcodeat (I) {<br/> return false; <br/>}< br/> return true; <br/>}</P> <p> // determines whether it is a Chinese character. <br/> function ischinese (name) {<br/> If (0 = Name. length) {<br/> return false; <br/>}< br/> for (I = 0; I <Name. length; I ++) {<br/> If (128 <name. charcodeat (I) {<br/> return true; <br/>}< br/> return false; <br/>}</P> <p> // determines whether sourcestr contains a character in errorstr. <br/> function contain (sourcestr, errorstr) {<br/> var I; <br/> for (I = 0; I <errorstr. length; I ++) {<br/> If (sourcestr. indexof (errorstr. charat (I) >=0) {<br/> return true; <br/>}< br/> return false; <br/>}</P> <p> // function used to determine the mobile phone number or bank account. Can be extended to domain name registration and so on <br/> function isnumber (string) {<br/> var C; <br/> var letters = "0123456789 "; // enter a custom value. That is, it can only be a number, applicable to mobile phone number or bank account verification <br/> If ('0' = string. charat (0) {<br/> return false; // The entered mobile phone number, cannot start with '0' <br/>}< br/>/* <br/> If ('0' = string. charat (string. length-1) {<br/> return false; // The entered mobile phone number, cannot end with '0' <br/>}< br/> */<br/> for (I = 0; I <string. length; I ++) {<br/> C = string. charat (I); <br/> If (0> letters. indexof (c) {<br/> return false; // only characters limited by letters can be entered <br/>}< br/> return true; <br/>}</P> <p> // Form Verification <Br/> function examine () {<br/> If ("" = Document. form11.username. Value |! Ischinese (document. form11.username. value) {<br/> alert ("the user name cannot be blank and can only be Chinese characters"); <br/> document. form11.username. focus (); <br/> return false; <br/>}< br/> If (6 <document. form11.username. value. length | 2> document. form11.username. value. length) {<br/> alert ("the number of Chinese characters in the user name is limited to 2 ~~ Between 6 "); <br/> document. form11.username. focus (); <br/> return false; <br/>}< br/> If ("" = document. form11.tel. value |! Isnumber (document. form11.tel. Value) | 11! = Document. form11.tel. value. length) {<br/> alert ("the mobile phone number cannot be blank and must consist of 11 Arabic numerals, and the first digit of the mobile phone number cannot be zero "); <br/> document. form11.tel. value = ""; <br/> document. form11.tel. focus (); <br/> return false; <br/>}< br/> If ("" = document. form11.oldpassword. value) {<br/> alert ("the original password cannot be blank"); <br/> document. form11.oldpassword. focus (); <br/> return false; <br/>}< br/> If ("" = document. form11.newpassword. value) {<br/> alert ("the new password cannot be blank"); <B R/> document. form11.newpassword. focus (); <br/> return false; <br/>}< br/> If ("" = document. form11.renewpassword. value) {<br/> alert ("the password cannot be blank"); <br/> document. form11.renewpassword. focus (); <br/> return false; <br/>}< br/> If (document. form11.newpassword. value! = Document. form11.renewpassword. value) {<br/> alert ("inconsistent passwords entered twice"); <br/> document. form11.newpassword. value = ""; <br/> document. form11.renewpassword. value = ""; <br/> document. form11.newpassword. focus (); <br/> return false; <br/>}< br/> // var idx = document. form11.email. value. indexof ("@"); <br/> // If (idx <= 0 | idx = document. form11.email. value. length-1) {// todo ....} <br/> If (null = document. form11.email. V Alue. match ("@") | contain (document. form11.email. value, "%/(/)> <") {<br/> alert ("Incorrect email format"); <br/> document. form11.email. focus (); <br/> return false; <br/>}< br/> If (confirm ("are you sure you want to register as a member of this site? /N please confirm !! ") {<Br/> return true; <br/>}else {<br/> return false; <br/>}< br/> </SCRIPT> <br/> <form name = "form11" id = "form11" Action = "#" Method = "Post"> <br/> User: <input type = "text" name = "username" id = "username"/> <br/> mobile phone: <input type = "text" name = "tel" id = "tel"/> <br/> original password: <input type = "password" name = "oldpassword" id = "oldpassword"/> <br/> new password: <input type = "password" name = "newpassword" id = "newpassword"/> <br/> confirm the password: <input type = "password" name = "renewpassword" id = "renewpassword"/> <br/> email address: <input type = "text" name = "email" id = "email"/> <br/> <input type = "button" value = "test form verification "onclick =" examine () "> & nbsp; <br/> <input type = "Submit" value = "click I can also verify" onclick = "javascript: Return examine ()"/> </form>
A confirmation box pops up when you use <input type = "button"/> to submit a form.
<Script language = "JavaScript"> <br/> function edit () {<br/> document. forms [0]. method. value = "edit"; <br/> document. forms [0]. submit (); <br/>}< br/> function del () {<br/> If (confirm ('Are you sure you want to delete the selected comment? ') {<Br/> document. forms [0]. method. value = "delete"; <br/> document. forms [0]. submit (); <br/>}< br/> </SCRIPT> <br/> <form action = "#" method = "Post"> <br/> input type = "hidden" name = "method" value = ""> <br/> <input type = "button" onclick = "Edit () "value =" edit "/> <br/> <input type =" button "onclick =" del () "value =" delete "/> <br/> </form>
When you send a request using the <a href = "#"> </a> link, a confirmation box is displayed.
<SCRIPT type = "text/JavaScript"> <br/> function del () {<br/> If (confirm ("are you sure you want to delete this article? /N please confirm! ") {<Br/> return true; <br/>}else {<br/> return false; <br/>}< br/> </SCRIPT> <br/> <a href = "#" onclick = "javascript: Return del () "> </a> <br/> <% -- <br/> method, <br/> <a href = "javascript: If (confirm ('Are you sure you want to delete it? ') {Location =' <% = request. getcontextpath () %>/Delete. jsp? Isdelete = true & page = 2'} "> Delete </a> <br/> -- %>