下面是验证的validation.js文件
var errMsg = [
' String length must be greater than 4 characters',
'名字必须汉字',
'年龄必须为数字',
'密码必须多于或等于 6 个字符。',
'验证密码与原密码不一致!',
'Email地址不合法!',
];
var pattern = [
/.{4,}/,
/^([\u4E00-\u9FA5]){1,}$/,
/^[0-9]{1,3}$/,
/.{6,}/,
'',
/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]{2,}(\.[a-z0-9]{2,5}){1,2}$/
];
function CheckLengthNG(TagValue,TagName,Message) {
if (!pattern[0].test($(TagValue).val())) {
$(TagName).html(Message + errMsg[0]);
return true;
}
else
{
$(Display).html('');
return false;
}
}
}
function showErrorMessage(TagName, ErrorMessage) {
var a = ErrorMessage.substring(ErrorMessage.indexOf('['), ErrorMessage.indexOf(']')+1)
var b = '<span style="color:skyblue">' + a + '</span>'
var ErrMsg = ErrorMessage.replace(a, b);
$(TagName).html(ErrMsg);
}
下面是使用的页面
@{
ViewBag.Title = "Document SIC";
//Layout = null;
}
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/common.js"></script>
<script type="text/javascript">
function InsertDocumentSIC() {
var SICNo = $('#txtSICNo').val();
var TemplateID = $('#selDocumentTemplate').val();
if (CheckLengthNG('#txtSICNo', '#SICspanErrorMessage', 'The SIC No ')) {
return;
}
var obj = GetTemplateID();
if (obj.statusCode != 0) { return; } else { var TemplateID = obj.TemplateID }
var url = "/Document/InsertDocumentSIC?TemplateID=" + TemplateID + "&SICNo=" + SICNo;
$.ajax({
url: url,
async: false,
type: "POST",
contentType: "application/json",
success: function (data) {
var objData = JSON.parse(data)
if (objData.statusCode != '0') {
alert(objData.statusMessage)
showErrorMessage('#SICspanErrorMessage', objData.statusMessage);
$('#txtSICNo').select();
}else
{
GetDocumentSIC();
$('#txtSICNo').val('');
}
}
});
}
</script>
<!--Attachment 2-->
<p id="pDocumentSICUserAuthority" >
<p class="row">
<label style="color:white">SIC No </label>
<input type="text" id="txtSICNo" />
<button class="btn btn-primary" onclick="InsertDocumentSIC()" id="btnDocumentAddSIC">Add SIC</button>
<span id="SICspanErrorMessage" style="color:red"> </span>
</p>
<p class="row table-responsive">
<table id="TableSIC" class="table table-bordered text-nowrap" style="color:white;background-color:transparent;">
<thead>
<tr>
<th>ID </th>
<th>SIC Title </th>
<th>SIC No </th>
<th>Revision </th>
<th>Effecitve Date </th>
<th>Digital Signature </th>
<th>Date </th>
<th>updQty </th>
<th>Delete </th>
<th>Upload </th>
</tr>
</thead>
<tbody></tbody>
</table>
</p>
</p>相关文章:
相关视频:
立即学习“前端免费学习笔记(深入)”;
以上就是自己写的前端验证--验证validation.js文件(附代码)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号