|
|
验证坐席号只能为10位以内的数字 例子
Reg.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><script type="text/javascript" src="reg.js"></script><title>无标题文档</title></head><body><form id="form1" name="form1" method="post" action=""> 坐席号 <label> <input name="workId" type="text" id="workId" onpropertychange="notNull(this,10)"/> </label> <p> <label> <input type="submit" name="Submit" value="提交" /> </label> </p></form></body></html>
Reg.js
function notNull(obj,maxlen){ if(obj.value.length>maxlen) { alert('文本框输入超出'+maxlen+'个长度'); obj.value=obj.value.substring(0,maxlen); } else{ if(/[^\d]/.test(obj.value)) obj.value=obj.value.replace(/[^\d]/,"");} }
需要注意的是这2个文件最好在同一个目录下 |
|