判断用户名是否有效
應用字符的ASCII碼來判斷用戶名是否有效,英文字母的ASCII范圍為65-90(大寫字母)和97-122(小寫字母),下劃線的ASCII碼為95,數字的ASCII碼范圍在47-58
創建StringUtil的JavaBean類,判斷用戶名是否有效
創建index.jsp頁面,輸入表單信息
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form action="check6.jsp" method="post"><table><tr><td align="right">請輸入用戶名:</td><td><input type="text" name="name"><font>只能由字母,數字或下劃線組成</font></td></tr><tr><td colspan="2" align="center"><input type="submit" value="驗證"></td></tr></table> </form> </body> </html>創建check.jsp驗證用戶輸入的字符串
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <%String name=request.getParameter("name"); %> <jsp:useBean id="strBean" class="com.cn.zj.bean.StringUtil6"></jsp:useBean> <jsp:setProperty property="str" name="strBean" value="<%=name %>"/> <table><tr><td align="right">輸入的用戶名為:</td><td><jsp:getProperty property="str" name="strBean"/></td></tr><tr><td align="right">是否有效:</td><td><jsp:getProperty property="valid" name="strBean"/></td></tr><tr><td align="right">提示信息:</td><td><jsp:getProperty property="cue" name="strBean"/></td></tr> </table> </body> </html>總結
- 上一篇: 判断用户输入的日期是否为当前日期
- 下一篇: 将指定日期字符串转换为Calendar对