December 2003
Intermediate to advanced
764 pages
24h 58m
English
Example 17-6 shows a modified version of the User Info page used in the examples in Chapter 10.
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>User Info Entry Form</title>
<script language="JavaScript"> <!-- Hide from browsers without JavaScript support function isValidForm(theForm) { if (isEmpty(theForm.userName.value)) { theForm.userName.focus( ); return false; } if (!isValidDate(theForm.birthDate.value)) { theForm.birthDate.focus( ); return false; } if (!isValidEmailAddr(theForm.emailAddr.value)) { theForm.emailAddr.focus( ); return false; } if (!isValidNumber(theForm.luckyNumber.value, 1, 100)) { theForm.luckyNumber.focus( ); return false; } return true; } function isEmpty(aStr) { if (aStr.length == 0) { alert("Mandatory field is empty"); return true; } return false; } function isValidDate(dateStr) { var matchArray = dateStr.match(/^[0-9]+-[0-1][0-9]-[0-3][0-9]$/) if (matchArray == null) { alert("Invalid date: " + dateStr); return false; } return true; } function isValidEmailAddr(emailStr) { var matchArray = emailStr.match(/^(.+)@(.+)\.(.+)$/) if (matchArray == null) { alert("Invalid email address: " + emailStr); return false; } return true; } function isValidNumber(numbStr, start, stop) { var matchArray = numbStr.match(/^[0-9]+$/) if ...Read now
Unlock full access