javascript验证,应使用c#语言的asp.net控件完成 [英] javascript validation that should be done using asp.net controls in c# language

查看:65
本文介绍了javascript验证,应使用c#语言的asp.net控件完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证文本框,单选按钮或下拉列表等简单字段.标签包含一个名称,该名称应验证这样在文本框中输入的详细信息.该字段不应为空,并且应包含有限的字符并且不应使用数字.如果未输入或未选择任何内容,则应显示错误消息. class ="h2_lin">解决方案

尝试一下:-

假设您有这样的形式:-

<form name="subscribe" id="subscribe_frm" action="#">
Your Name: <input type="text" name="name" id="txt_name" />
<input type="button" name="submit" value="Submit">
onclick="validateTextBox();" onleyup="validChar();" />
</input></form>


<script language="javascript">
function validateTextBox()
{
 var txtN=document.getElementById(''txt_Name'');
 if(txtN.value=='''')
 {
  alert(''Textbox can''t be blank'');
  return false;
 }
 if(txtN.length>=[type the no of charaters you want the text to be limit])
 {
  alert(''[Your prompt]'');
  return false;
 }
}
function validChar()
{
 var txtN=document.getElementById(''txt_Name'');
 if(!txtN.value.match(/^[a-zA-Z]+


/)) { alert(''Enter only Characters''); return false; } } </script>



如果可以帮助您,请不要忘记将其标记为您的答案.欢迎查询


Javascript代码:


< script language ="javascript" type ="text/javascript">
函数validate()
{
如果(document.getElementById(<%= txt_uname.ClientID%>").value ==")
{
alert("UserName Feild不能为空");
document.getElementById(<%= txt_uname.ClientID%>").focus();
返回false;
}
如果(document.getElementById(<%= txt_pwd.ClientID%>").value ==")
{
alert(密码密码不能为空");
document.getElementById(<%= txt_pwd.ClientID%>").focus();
返回false;
}
如果(document.getElementById(<%= txt_cpwd.ClientID%>").value ==")
{
alert(确认密码无效不能为空");
document.getElementById(<%= txt_cpwd.ClientID%>").focus();
返回false;
}

如果(document.getElementById(<%= txt_age.ClientID%>").value ==")
{
alert("Age Feild不能为空");
document.getElementById(<%= txt_age.ClientID%>").focus();
返回false;
}
if(document.getElementById(<%= txt_email.ClientID%>").value ==")
{
alert(电子邮件ID不能为空");
document.getElementById(<%= txt_email.ClientID%>").focus();
返回false;
}
var emailPat =/^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}] | [A-Za-z] \ w *(\.[A-Za-z] \ w *)+)


i need validation for an simple field like text box,radio button or dropdown. label contains a name it should validate the details entering in the textbox like that.the field should not be empty and it should contain limited characters and no numeric should be allowed.if nothing is entered or selected it should display an error message.

解决方案

try this:-

Lets say you have a form like this:-

<form name="subscribe" id="subscribe_frm" action="#">
Your Name: <input type="text" name="name" id="txt_name" />
<input type="button" name="submit" value="Submit">
onclick="validateTextBox();" onleyup="validChar();" />
</input></form>


<script language=""javascript"">
function validateTextBox()
{
 var txtN=document.getElementById(''txt_Name'');
 if(txtN.value=='''')
 {
  alert(''Textbox can''t be blank'');
  return false;
 }
 if(txtN.length>=[type the no of charaters you want the text to be limit])
 {
  alert(''[Your prompt]'');
  return false;
 }
}
function validChar()
{
 var txtN=document.getElementById(''txt_Name'');
 if(!txtN.value.match(/^[a-zA-Z]+


/)) { alert(''Enter only Characters''); return false; } } </script>



Please don''t forget to mark this as your answer if it helps you out. Queries are welcome


Javascript code :


<script language="javascript" type="text/javascript">
function validate()
{
if (document.getElementById("<%=txt_uname.ClientID%>").value=="")
{
alert("UserName Feild can not be blank");
document.getElementById("<%=txt_uname.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txt_pwd.ClientID%>").value=="")
{
alert("Password Feild can not be blank");
document.getElementById("<%=txt_pwd.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txt_cpwd.ClientID%>").value=="")
{
alert("Confirm Passowrd Feild can not be blank");
document.getElementById("<%=txt_cpwd.ClientID%>").focus();
return false;
}

if (document.getElementById("<%=txt_age.ClientID%>").value=="")
{
alert("Age Feild can not be blank");
document.getElementById("<%=txt_age.ClientID%>").focus();
return false;
}
if(document.getElementById("<%=txt_email.ClientID %>").value=="")
{
alert("Email id can not be blank");
document.getElementById("<%=txt_email.ClientID %>").focus();
return false;
}
var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)


这篇关于javascript验证,应使用c#语言的asp.net控件完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆