javascript - 如何实现jquery验证

标签 javascript php jquery html

你好, friend 们,你能帮我解决验证问题吗?如何使用某些特定的条件字段进行 jQuery 验证。我尝试过但是没有解决。请任何人解决这个正确的代码,其他人可以在这个问题中回答我。

<html>
<head>
<title>data for validation</title>
<script src="jquery-1.12.0.min.js" type="text/javascript"></script>
 <script src="jquery.validate.min.js" type="text/javascript"></script>
 <script>
 $(document).ready(function(){
     $("#frm").validate({
                 rules:{
                     username:{
                         required:true,
                         myupper:true
                     },

                     password:{
                         required:true,
                         minlength:3
                     },
                 },messages:{
                    username:{
                         required:"User Name Required"

                     },
                     password:{
                         required:"password Required",

                     },
                 }
 });
 });
 </script>
</head>
<body>
    <form action="" method="post" id="frm">
       <table border="1" align="center">
         <h1 align ="center" style="color:red">Registration form!!!</h1>
         <tr>
           <th>username</th>
           <td><input type="text" pattern="^([a-zA-Z0-9)$" maxlength="10" name="username" placeholder="Enter username"></td>
        </tr>
        <tr>
          <th>password</th>
          <td><input type="password" maxlength="10" name="password" placeholder="Enter password"></td>
        </tr>
        <tr>
        <tr>
           <td colspan="2" align="center"><input type="submit"  name="submit" value="submit"/></td>
        </tr>
     </table>
   </form>
</body>
</html>

最佳答案

尝试这样的事情:

$('#form_id').validate({
    rules:{
        name : 
        {
            required: true
        },
        email : 
        {
            required: true,
            email : true
        },
        and so on
    },
    messages:{
        name : 
        {
            required: "message"
        },
        email : 
        {
            required: "message",
            email : "message"
        }
    }
});

Documentation

关于javascript - 如何实现jquery验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39346836/

相关文章:

javascript - 为什么 Prettier 不允许我将函数参数分成多行?

javascript - 在 html 文本区域中按 Enter 键时如何使用 jquery 添加换行符

javascript - 一列的jqgrid自定义编辑行为

带有两个文件夹的PHP页面登录

php - mysqldump 停止新的 apache 升级

php - 使用 PHP ftp_get() 检索具有通配 rune 件名的文件

jquery - 使用 jQuery 通过 .ajax() 传递 JSON

javascript - 删除 Fabric.js 中选定的对象矩形

javascript - appendChild 不会将节点添加到子级列表的末尾

jquery - 如何在具有现有记录的 json 数据表顶部添加新行