下面是验证的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-->
<div id="divDocumentSICUserAuthority" >
<div 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>
</div>
<div 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>
</div>
</div>