Java background developed form validation before submission

  • 2020-06-03 06:24:40
  • OfStack

Without further ado, the specific code is as follows:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
<%@ page import="java.util.*" %> 
<%@ page import="java.sql.*" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title> The form submission </title> 
    <p align="center"><b> The form submission </b><br></p> 
      <div align="left"> 
        <table height="60" border="0" align="left"> 
              <form name="channelform" action="addChannel.jsp" 
               onsubmit="return validate_channel_info(this);" method="post"> 
                 The name :  
                <input type="text" name="channelname" /> 
                <br /> 
                <input type="text" name="channelid" /> 
                <br /> 
                <input type="submit" value=" submit ">                  
        <script type="text/javascript"> 
          function validate_channel_info(channelform) 
              alert(" Please enter the correct name "); 
              return false; 
            else if(!isNumber(channelform.channelid.value)) 
              alert(" Please enter legal ID"); 
              return false; 
            return true; 
          function isNumber(str)     //  Determine if it is a non-negative integer  
            var rx = /^[0-9]+$/; 
            return rx.test(str); 

Related articles: