bdjsp
<%@ page contentType="text/html;charset=gb"%> <% //接受表单提交的字符串 /* 数据只能为azAZ的字符的正则表达式的例子 正则表达式在做程序登陆的过程非常重要不然用´ or ´ 等语句就可以很容易绕过您的程度判断 作者高颂 QQ: 一个简单的例子但是很有用希望起到抛砖引玉的作用 */ String temp ="我是非法的字符"; String name = requestgetParameter("name"); //应收金额 String pass = requestgetParameter("pass"); if (name==null){ name=temp; } if (pass==null){ pass=temp; } %>
<%!private boolean regex(String str){ javautilregexPattern p=null; //正则表达式 javautilregexMatcher m=null; //操作的字符串 boolean value=true; try{ p = javautilregexPatterncompile("[^AZaz]"); m = pmatcher(str); if(mfind()) {
value=false; } }catch(Exception e){} return value; } %>
<html> <title>信息输入表单</title> <body> <form action = "bdjsp" method = "get" > <div align="center"><font color="#FF">数据只能为azAZ的字符的正则表达式的例子</font> <table border = ""> <tr> <td bgcolor = "yellow">用户</td> <td><input name = "name" type = "text" id="name"></td> </tr> <tr> <td width="" bgcolor = "yellow">密码</td> <td width=""> <input name = "pass" type = "text" id="input"></td> </tr> <tr> <td colspan = "" align = "center"><input name="submit" type = "submit" value = "确定"> <input name="reset" type = "reset" value = "取消"> </td> </tr> <tr> <td colspan = "" align = "center">消息提示 <% //判断: if(!regex(name)){ outprint("用户名只能是azAZ的字符"); return;//跳出程序只行 }
outprint("恭喜您的数据录入合法了<br>"+"您录入的名字是"+name+"<br>您录入的密码是"+pass);
%> </td> </tr> </table> </div> </form> </body> </html> |