判断用户名是否有效
應(yīng)用字符的ASCII碼來(lái)判斷用戶名是否有效,英文字母的ASCII范圍為65-90(大寫(xiě)字母)和97-122(小寫(xiě)字母),下劃線的ASCII碼為95,數(shù)字的ASCII碼范圍在47-58
創(chuàng)建StringUtil的JavaBean類(lèi),判斷用戶名是否有效
創(chuàng)建index.jsp頁(yè)面,輸入表單信息
<%@ 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">請(qǐng)輸入用戶名:</td><td><input type="text" name="name"><font>只能由字母,數(shù)字或下劃線組成</font></td></tr><tr><td colspan="2" align="center"><input type="submit" value="驗(yàn)證"></td></tr></table> </form> </body> </html>創(chuàng)建check.jsp驗(yàn)證用戶輸入的字符串
<%@ 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>總結(jié)
- 上一篇: 判断用户输入的日期是否为当前日期
- 下一篇: 将指定日期字符串转换为Calendar对