判断用户名是否有效
应用字符的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对