javascript can be used to authenticate these input data in an HTML form before the data is sent to the server
The typical form data that is validated by JavaScript is: Does the user fill in the required items in the form? is the e-mail address that the user entered legal? Has the user entered a valid date? Does the user enter text in the Data field (numeric field)? Required (or required) items The following function is used to check whether the user has filled out the required (or required) items in the form. If a required or required option is blank, the warning box pops up and the function returns a value of false, otherwise the function returns True (meaning the data is OK): The code is as follows: function validate_required (field, Alerttxt) {with (field) {if (value==null| | value== "") {alert (alerttxt); return false} else {return true}} e-mail authentication (verify mailbox) The following function checks whether the data entered The basic syntax that matches the e-mail address. Meaning, the data entered must contain the @ symbol and the dot (.) sign. At the same time, @ can not be the first character of the mail address, and after @ must have at least one point number: Code as follows: function Validate_email (field,alerttxt) {with (field) {Apos=value.indexo F ("@") Dotpos=value.lastindexof (".") if (apos<1| | DOTPOS-APOS<2) {alert (alerttxt); return false} else {return true}} instance: Code as follows: <HT ml> <head> <script type= "Text/javascript" > Function Validate_email (field,alerttxt) {with (field) {apos= Value.indexof ("@") Dotpos=value.lastindexof (".") if (apos<1| | DOTPOS-APOS<2) {AleRT (Alerttxt); return false} ' else {return true}} ' function Validate_form (thisform) {with (thisform) {if (Validate _email (email, "Not a valid e-mail address!") ==false) {email.focus (); return False}}} </script> </head> <body> <form action= "Submi Tpage.htm "onsubmit=" return Validate_form (this); "method=" POST "> Email: <input type=" text "name=" Email "size=" 30 "> <input type=" Submit "value=" Submit "> </form> </body> </html>