Home > Web Front-end > JS Tutorial > body text

Front-end verification written by myself--verification validation.js file (with code)

php是最好的语言
Release: 2018-08-04 09:53:42
Original
1915 people have browsed it

下面是验证的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 = &#39;<span style="color:skyblue">&#39; + a + &#39;</span>&#39;
    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      = $(&#39;#txtSICNo&#39;).val(); 
            var TemplateID = $(&#39;#selDocumentTemplate&#39;).val();

            if (CheckLengthNG(&#39;#txtSICNo&#39;, &#39;#SICspanErrorMessage&#39;, &#39;The SIC No &#39;)) {
                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 != &#39;0&#39;) { 
                        alert(objData.statusMessage)
                        showErrorMessage(&#39;#SICspanErrorMessage&#39;, objData.statusMessage);
                        $(&#39;#txtSICNo&#39;).select();
                    }else
                    {
                        GetDocumentSIC();
                        $(&#39;#txtSICNo&#39;).val(&#39;&#39;);
                    }
                }
            });
        }
 

</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>
Copy after login

Related articles:

An addition and subtraction verification code within 10 written by yourself

How to write the login and registration front-end verification input format

Related videos:

JS development verification form tutorial

The above is the detailed content of Front-end verification written by myself--verification validation.js file (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template