<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="ext-3.2.1/resources/css/ext-all.css"/>
<script type="text/javascript" src="ext-3.2.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.2.1/ext-all.js"></script>
<script>
Ext.onReady(function(){
Ext.QuickTips.init();
//js验证ip地址函数
function checkip(ip)
{
var pcount = 0
var ip_length = ip.length
var ip_letters = "1234567890."
for (p=0; p < ip_length; p++)
{
var ip_char = ip.charAt(p)
if (ip_letters.indexOf(ip_char) == -1)
{
return false
}
}
for (var u = 0; u < ip_length; u++) { (ip.substr(u,1) == ".") ? pcount++ : pcount }
if(pcount != 3) { return false }
firstp = ip.indexOf(".")
lastp = ip.lastIndexOf(".")
str1 = ip.substring(0,firstp)
ipstr_tmp = ip.substring(0,lastp)
secondp = ipstr_tmp.lastIndexOf(".")
str2 = ipstr_tmp.substring(firstp+1,secondp)
str3 = ipstr_tmp.substring(secondp+1,lastp)
str4 = ip.substring(lastp+1,ip_length)
if (str1 == '' || str2 == '' || str3 == '' || str4 == '') { return false }
if (str1.length > 3 || str2.length > 3 || str3.length > 3 || str4.length > 3) { return false }
if (str1 <= 0 || str1 > 255) { return false }
else if (str2 < 0 || str2 > 255) { return false }
else if (str3 < 0 || str3 > 255) { return false }
else if (str4 < 0 || str4 > 255) { return false }
return true
}
//js验证mac地址函数
function check_mac(mac)
{
//mac地址正则表达式
var reg_name=/[A-F/d]{2}-[A-F/d]{2}-[A-F/d]{2}-[A-F/d]{2}-[A-F/d]{2}-[A-F/d]{2}/;
if(!reg_name.test(mac)){
return false;
}
return true;
}
//验证PORT
function isPort(str) {
return (isNumber(str) && str < 65536);
}
function isNumber(s) {
var regu = "^[0-9]+$";
var re = new RegExp(regu);
if (s.search(re) != -1) {
return true;
} else {
return false;
}
}
//js验证时间函数
function check_time(time)
{
var rr=/^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/;
if (!rr.test(time))
{
return false;
}
return true;
}
var addForm = new Ext.form.FormPanel({
bodyStyle:'padding:10px 20px 0',
frame:true,
border:false,
labelWidth:80,
width:310,
height:200,
lableAlign:'right',
defaultType:'textfield',
items:[
{
fieldLabel:"IP 地 址",
name:"ipaddress",
validator:checkip,
invalidText:"不是有效的IP地址!格式为:127.0.0.1",
anchor:'95%'
},{
fieldLabel:"MAC地址",
name:"macaddress",
validator:check_mac,
invalidText:"输入的MAC地址无效!格式为00-24-21-19-BD-E4",
anchor:'95%'
},{
fieldLabel:"端 口 号",
name:"port",
validator:isPort,
invalidText:"不是有效的端口号!必须为数字",
anchor:'95%'
},{
fieldLabel:"创建时间",
name:"createdate",
validator:check_time,
invalidText:"输入的时间无效!格式为2009-07-02 09:18:00",
anchor:'95%'
}
]
});
var win = new Ext.Window({
renderTo:document.body,
title:"新增窗口",
width:320,
height:250,
mode:true,
buttonAlign:'center',
items:addForm,
buttons:[
{text:"保存"},
{text:"重置"}
]
});
win.show();
});
</script>
</head>
<body>
</body>
</html>