JS非空验证

代码如下:

<body>
<table>
<tr>
<td>姓名:</td>
<td><input type="text" name="TrueName" id="TrueName" /></td>
</tr>

<tr>
<td colspan="2">
<input type="submit" value="submit"  onclick="return check();" />
</td>
</tr>
</table>

</body>

<script language="JavaScript">
function Check()
{
 if(document.getElementById(‘TrueName‘).value==‘‘) {
  alert(‘必须输入姓名!‘);
  document.getElementById(‘TrueName‘).focus();
  return false;
 }

 if(document.getElementById(‘Identity‘).value==‘‘) {
  alert(‘必须输入身份证号码!‘);
  document.getElementById(‘Identity‘).focus();
  return false;
 }

 if(document.getElementById(‘Tel‘).value==‘‘) {
  alert(‘必须输入联系电话!‘);
  document.getElementById(‘Tel‘).focus();
  return false;
 }

 if(document.getElementById(‘Address‘).value==‘‘) {
  alert(‘必须输入联系地址!‘);
  document.getElementById(‘Address‘).focus();
  return false;
 }

 if(document.getElementById(‘PassWord‘).value==‘‘) {
  alert(‘密码不能为空!‘);
  document.getElementById(‘PassWord‘).focus();
  return false;
 }

 if(document.getElementById(‘PassWord‘).value!=document.getElementById(‘RPass‘).value) {
  alert(‘两次输入的密码不一致!‘);
  document.getElementById(‘PassWord‘).focus();
  return false;
 }
}
</script>

<script language="JavaScript">
function Check()
{
 if(document.getElementById(‘TrueName‘).value==‘‘) {
  alert(‘必须输入姓名!‘);
  document.getElementById(‘TrueName‘).focus();
  return false;
 }

 if(document.getElementById(‘Identity‘).value==‘‘) {
  alert(‘必须输入身份证号码!‘);
  document.getElementById(‘Identity‘).focus();
  return false;
 }

 if(document.getElementById(‘Tel‘).value==‘‘) {
  alert(‘必须输入联系电话!‘);
  document.getElementById(‘Tel‘).focus();
  return false;
 }

 if(document.getElementById(‘Address‘).value==‘‘) {
  alert(‘必须输入联系地址!‘);
  document.getElementById(‘Address‘).focus();
  return false;
 }

 if(document.getElementById(‘PassWord‘).value==‘‘) {
  alert(‘密码不能为空!‘);
  document.getElementById(‘PassWord‘).focus();
  return false;
 }

 if(document.getElementById(‘PassWord‘).value!=document.getElementById(‘RPass‘).value) {
  alert(‘两次输入的密码不一致!‘);
  document.getElementById(‘PassWord‘).focus();
  return false;
 }
}
</script>

  

时间: 2024-08-25 01:06:39

JS非空验证的相关文章

easyui-combobox非空验证等

js代码 1 function validate(){ 2 $.extend($.fn.validatebox.defaults.rules, { 3 maxLength: { 4 validator: function(value, param){ 5 return value.length <= param[0]; 6 }, 7 message: '最多输入 {0} 位' 8 }, 9 onlyLength:{ 10 validator: function(value, param){ 11

.NET开源工作流RoadFlow-Bug修改-1.8.2表单验证时ueditor编辑非空验证无效

RoadFlow生成的表单,Ueditor编辑器不能进行非空验证的BUG修改: 1.修改控制器:WorkFlowFormDesignerController红框处: 2.修改js文件:Scripts/roadui.init.js 3.修改文件:Scripts/FlowRun/Forms/common.js 在这个Case后面增加: case "flow_html": if (filedshow == 0) { $control.html(initValue); } else if (f

Atitit &#160;验证 数字验证 非空验证的最佳算法 &#160;h5

Atitit  验证 数字验证 非空验证的最佳算法  h5 <td><select class="searchBox-select"   style="height:25px;" id2="branch_id" id="objid" name="objid" required  > <option value="">--物品</option>

php非空验证

我想说这种方法是不是很常用的非空验证,现在的普遍使用的是javascript来验证非空,但是作为学习php的一些知识点,还是可以看看的. 先来看看commit.php中的方法 <?php $db = mysql_connect('localhost','root','Ctrip07185419'); mysql_select_db('moviesite',$db) or die(mysql_error($db)); mysql_query('set names "gb2312"'

[Teamcenter 2007 开发系列] web 非空验证

前言 TC 2007 的Web 端,页面简洁也简单. 非空验证的话,直接在后面加上一个 红箭头+ "Required value is not specified." 这样一些红色的提示信息. 而这种验证看上去又是和CF端的form 的定义管理起来的. 定义成require 的属性会做这种验证. 那么在web 端实现的机制是怎样的呢? 是否可以不和CF端绑定,在 Web端直接进行这种验证呢? 实现机制 以创建一个物件为例,关键的action-component 是 ModelEntit

JavaWeb 学习008-今日问题(非空验证尚未解决) 2016-12-2

1. 学生模块list页面 不能正常跳转 说是找不到stuid属性,但是我在entity里面和数据库建表的属性就是stuid:Grade模块代码一样,却可以正常运行 这是什么问题? <c:forEach items="slist" var="student"> <tr> <td>${student.stuid}</td> <td>${student.stuname}</td> <td>

C# 实体类非空验证

public class BillReceiveModelDTO { /// <summary> /// /// </summary> [DataMember] [Required(ErrorMessage = "非空")] public string orderNo { set; get; } } //验证private static IEnumerable<string> VerifyTelegram(BillReceiveModelDTO te

jQuery.validator的非空验证 唯一性验证

<!--editpanl start--> <div class="modal fade" id="editpanl" data-backdrop="static"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header">

20150528&mdash;html使用Jquery遍历text文本框的非空验证

<script src="jquery-1.7.2.min.js" type="text/javascript"></script> <script type="text/jscript"> function notnull() { var count = 0; $("input[type=text]").each(function () { if ($(this).val() == '')