我的Prototype模式框架

最近看了大叔关于JavaScript的手记 感觉不错,自己开发一个利用原型模式的JavaScript库雏形,求各位指教

//作者:李腾飞
//
开发时间:2012-1-5
//
JScript脚本库
//
Email
var Email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
//手机号码
var mobile = /^((13[0-9]{1})|159|153|18[0-9]{1})+\d{8}$/;
//固定电话(不包含分机)
var Phone = /\d{7|8}$/;
var _instance = null;
var Instance = function() {
if (_instance == null)
_instance = new Tomosoft();
return _instance;
};

var Tomosoft = function() {


};

Tomosoft.prototype.checkEmail = function(text, returnMsg) {
//debugger;
if (Instance().checkNull(text, returnMsg)) {
if (!Email.test(text)) {
alert(returnMsg);
return false;
}
} else {
return false;
}
return true;
};

Tomosoft.prototype.checkMobile = function(text, returnMsg) {
if (Instance().checkNull(text, returnMsg)) {
if (!mobile.test(text)) {
alert(returnMsg);
return false;
}
} else {
return false;
}
return true;
};

Tomosoft.prototype.checkNull = function(text, returnMsg) {
if (text.length <= 0) {
alert(returnMsg);
return false;
}
return true;
};

Tomosoft.prototype.checkPhone = function(text, returnMsg) {
if (checkNull(text, returnMsg)) {
if (!Phone.test(text)) {
alert(returnMsg);
return false;
}
} else {
return false;
}
return true;
};

Tomosoft.prototype.checkLength = function(text, minLength, maxLength, returnMsg) {
if (text.length > minLength && text.length <= maxLength)
return true;
else {
alert(returnMsg);
return false;
}
};

前台调用

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JScript._Default" %>

<!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 runat="server">
<title></title>

<script type="text/javascript" src="jquery-1.6.4.min.js"></script>

<script type="text/javascript" src="Tomosoft.JScriptFreamwork.js"></script>

<script type="text/javascript">
var Tomo = new Tomosoft();
function check() {
if (!Tomo.checkNull($("#Text1").val(), "姓名不能为空!") || !Tomo.checkLength($("#Text1").val(), 0, 10, "长度超出限制!")) {
return false;
}
if (!Tomo.checkEmail($("#Text2").val(), "请输入正确的Email地址!")) {
return false;
}
return true;
}
</script>

</head>

<body>
<form id="form1" runat="server">
<div>
<input id="Text1" type="text" />
<input id="Text2" type="text" />
<input id="Text3" type="text" />
<asp:Button ID="Button1" runat="server" OnClientClick="return check();"
Text
="确 认" onclick="Button1_Click" />
</div>
</form>
</body>
</html>


不知道各位有何看法可以留言给我~~

posted @ 2012-01-05 14:10  tf.li  阅读(439)  评论(0编辑  收藏  举报