在线实时检查js与.net脚本
在表单中加上
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100px">店铺名称<font color="#FF0000">*</font></td>
<td width="210px"><asp:TextBox CssClass="input1" ID="txtName" runat="server" Width="200px" onfocus="javascript:changetips1();" onblur="javascript:ckName(this);" tabindex="1"></asp:TextBox></td>
<td><div id="<%=txtName.ClientID %>_tips" class="tips-default">请输入您的店铺名称</div></td>
</tr>
<tr>
<td>你的店铺地址<font color="#FF0000">*</font></td>
<td><asp:TextBox CssClass="input1" ID="txtNameURL" runat="server" Width="200px" onfocus="javascript:changetips2();" onblur="javascript:ckNameURL(this);" tabindex="2"></asp:TextBox></td>
<td><div id="<%=txtNameURL.ClientID %>_tips" class="tips-default">请输入您的店铺地址。</div></td>
</tr>
</table>
在.cs文件中加上
btSubmit.Attributes.Add("onclick", "return regcheck()");
<script language="javascript">
<!--
var strNumber=0;
tipsmsg=new Array();
tipsmsg[100]="请输入您的店铺名称";
tipsmsg[101]="正在检测你输入的帐户是否可用…";
tipsmsg[102]="此店铺已经有人注册了。";
tipsmsg[103]="恭喜!你的帐户符合要求,并可以使用。";
tipsmsg[104]="你输入的字数不符合要求,请输入4-100个字符。";
tipsmsg[200]="请输入您的店铺地址";
tipsmsg[201]="正在检测你输入的店铺地址是否可用…";
tipsmsg[202]="此店铺地址已经有人注册了。";
tipsmsg[203]="恭喜,你的店铺地址符合要求,并可以使用。";
tipsmsg[204]="你输入的字数不符合要求,请输入4-100个字符。";
tipsmsg[300]="请输入您的掌柜名称";
tipsmsg[301]="掌柜名称字数太少,输入不少于2个字符的密码。";
tipsmsg[302]="掌柜名称填写正确。";
tipsmsg[400]="请选择地址";
tipsmsg[1000]="请确认已阅读并认同<a href=/"/help/agreement.gs/" target=/"_blank/">使用协议</a>及<a href=/"/help/notice.gs/" target=/"_blank/">用户须知</a>。";
name=Array('{}',100,'tips-default');
nameURL=Array('',200,'tips-default');
shopKeeper=Array('',300,'tips-default');
function changetips(name,msgid,styles){
obj=document.getElementById(name+'_tips');
obj.innerHTML=tipsmsg[msgid];
obj.className=styles;
}
function ckName(obj){
if(obj.value.length<4 || obj.value.length>100){
changetips('<%=txtName.ClientID %>',104,'tips-error');
return false
}else{
changetips('<%=txtName.ClientID %>',101,'tips-loading');
PageMethods.GetExistName(obj.value,'<%=txtName.ClientID %>',GoResult);
return true;
}
}
function ckNameURL(obj){
if(obj.value.length<4 || obj.value.length>200){
changetips('<%=txtNameURL.ClientID %>',104,'tips-error');
return false
}else{
changetips('<%=txtNameURL.ClientID %>',201,'tips-loading');
PageMethods.GetExists_NameURL(obj.value,'<%=txtNameURL.ClientID %>',GoResult);
return true;
}
}
function ckShopKeeper(obj){
if(obj.value.length<2){
changetips('<%=txtShopKeeper.ClientID %>',301,'tips-error');
return false
}else{
changetips('<%=txtShopKeeper.ClientID %>',302,'tips-pass');
return true;
}
}
function GoResult(result)
{
eval(result);
}
function regcheck(){
var strBool;
var intflag=0;
var strCheckValue=window.document.getElementById('<%=txtName.ClientID %>');
strBool=ckName(strCheckValue);
if(!strBool)
{
intflag++;
}
var strCheckValue=window.document.getElementById('<%=txtNameURL.ClientID %>');
strBool=ckNameURL(strCheckValue);
if(!strBool)
{
intflag++;
}
var strCheckValue=window.document.getElementById('<%=txtShopKeeper.ClientID %>');
strBool=ckShopKeeper(strCheckValue);
if(!strBool)
{
intflag++;
}
strCheckValue=window.document.getElementById('<%=lstProvince.ClientID %>');
if(strCheckValue.value=="-1"){
changetips('<%=lstProvince.ClientID %>',400,'tips-error');
intflag++;
}
strCheckValue=window.document.getElementById('<%=lstCity.ClientID %>');
if(strCheckValue.value=="-1"){
changetips('<%=lstProvince.ClientID %>',400,'tips-error');
intflag++;
}
strCheckValue=window.document.getElementById('<%=cbAgreement.ClientID %>');
if(!strCheckValue.checked){
changetips('<%=cbAgreement.ClientID %>',1000,'tips-error');
intflag++;
}
if(intflag>0){
return false;
}
else
{
return true;
}
}
//判断用户名是否符合要求
function usernamecheck(string){
if((string.length<4)||(string.length>20)){return false;}
var re;
re=new RegExp("^[a-z|A-Z|0-9][a-z|A-Z|0-9|-]+$");
return re.test(string);
}
//判断密码是否符合规范
function passwordcheck(string){
var re;
re=new RegExp("^[0-9]+$");
return !re.test(string);
}
//判断电子邮箱是否符合规范
function emailcheck(string){
var re;
re=new RegExp("^[//w-_//.]+@([a-z|0-9|-]+//.)+[a-z]{2,5}$");
return re.test(string.toLowerCase());
}
//判断字符串的字节数
function strlen(string){
var str="";
str=string;
str=str.replace(/[^/x00-/xff]/g,"**");
return str.length;
}
function changetips1()
{
changetips('<%=txtName.ClientID %>',100,'tips-show');
}
function changetips2()
{
changetips('<%=txtNameURL.ClientID %>',200,'tips-show');
}
function changetips3()
{
changetips('<%=txtShopKeeper.ClientID %>',300,'tips-show');
}
-->
</script>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.Script.Services;
public partial class Bussines_RegisterShop : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDefault();
}
btSubmit.Attributes.Add("onclick", "return regcheck()");
}
protected void LoadDefault()
{
ListItem itemTop;
itemTop = new ListItem("[选择]", "-1");
DataTable dtArea;
QianBianWanHua_BLL.QB_Area bll = new QianBianWanHua_BLL.QB_Area();
dtArea = bll.ListProvinces().Tables[0];
lstProvince.DataSource = dtArea;
lstProvince.DataTextField = "AreaName";
lstProvince.DataValueField = "AreaCode";
lstProvince.DataBind();
itemTop = new ListItem("请选择", "-1");
lstProvince.Items.Insert(0, itemTop);
lstCity.Items.Insert(0, itemTop);
}
protected void lstProvince_SelectedIndexChanged(object sender, EventArgs e)
{
lstCity.Items.Clear();
string _strAreaCode = lstProvince.SelectedValue;
DataTable dtArea = new QianBianWanHua_BLL.QB_Area().ListCity(_strAreaCode).Tables[0];
lstCity.DataSource = dtArea;
lstCity.DataTextField = "AreaName";
lstCity.DataValueField = "AreaCode";
lstCity.DataBind();
ListItem itemTop = null;
if (dtArea.Rows.Count > 0)
{
itemTop = new ListItem("请选择", "-1");
}
else
{
itemTop = new ListItem(lstProvince.SelectedItem.Text, lstProvince.SelectedValue);
}
lstCity.Items.Insert(0, itemTop);
}
[WebMethod]
public static string GetExistName(string strValue, string ControlId)
{
QianBianWanHua_BLL.QB_Shop bll = new QianBianWanHua_BLL.QB_Shop();
bool _bResult = false;
_bResult = bll.Exists_Name(0, strValue);
if (_bResult)
{
return "parent.changetips('" + ControlId + "',102,'tips-error');parent." + ControlId + "=Array('" + strValue + "',102,'tips-error');";
}
else
{
return "parent.changetips('" + ControlId + "',103,'tips-pass');parent." + ControlId + "=Array('" + strValue + "',103,'tips-pass');";
}
}
[WebMethod]
public static string GetExists_NameURL(string strValue, string ControlId)
{
QianBianWanHua_BLL.QB_Shop bll = new QianBianWanHua_BLL.QB_Shop();
bool _bResult = false;
_bResult = bll.Exists_NameURL(0, strValue);
if (_bResult)
{
return "parent.changetips('" + ControlId + "',202,'tips-error');parent." + ControlId + "=Array('" + strValue + "',202,'tips-error');";
}
else
{
return "parent.changetips('" + ControlId + "',203,'tips-pass');parent." + ControlId + "=Array('" + strValue + "',203,'tips-pass');";
}
}
protected void btSubmit_Click(object sender, EventArgs e)
{
string _strUserId=Common.GetUserId();
string _strName = txtName.Text;
string _strNameURL = txtNameURL.Text;
string _strShopKeeper = txtShopKeeper.Text;
string _strLogo = txtLogo.Value;
string _strNotice = txtNotice.Value;
string _strArea = "";
bool _blnExist = false;
if (lstCity.SelectedValue != "-1")
{
_strArea = lstCity.SelectedValue;
}
else
{
_strArea = lstProvince.SelectedValue;
}
string _strIntroduce = txtIntroduce.Value;
QianBianWanHua_Model.QB_Shop model = new QianBianWanHua_Model.QB_Shop();
model.AreaId = _strArea;
model.BuyCredit = 0;
model.CreateDate = DateTime.Now;
model.Introduce = _strIntroduce;
model.Name = _strName;
model.NameURL = _strNameURL;
model.SellCredit = 0;
model.ShopKeeper = _strShopKeeper;
model.Tuthentication = 0;
model.UserId = int.Parse(_strUserId);
model.Logo = _strLogo;
model.Notice = _strNotice;
QianBianWanHua_BLL.QB_Shop bll = new QianBianWanHua_BLL.QB_Shop();
_blnExist = bll.Exists_Name(0, model.Name);
if (_blnExist)
{
QianBianWanHua_Common.MessageBox.Show(this, "此店铺已经有人注册了");
return;
}
_blnExist = bll.Exists_NameURL(0, model.NameURL);
if (_blnExist)
{
QianBianWanHua_Common.MessageBox.Show(this, "此店铺地址已经有人注册了");
return;
}
int _intResult = bll.Add(model);
if (_intResult > 0)
{
QianBianWanHua_Common.MessageBox.Show(this, "注册成功");
}
else
{
QianBianWanHua_Common.MessageBox.Show(this, "注册失败");
}
}
}