-1

我有一个注册表单,其中我使用了 JavaScript 表单验证器

我的表格

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
    <form class="form-group" method="post" id="contact-form">
        {% csrf_token %}

        <input type"text" name="username" placeholder="userid" id="id_username"/>
        <input type"email" name="email" placeholder="email" id="id_email"/>
        <input type"password" name="password1" placeholder="password1" id="id_password1"/>
        <input type"password" name="password2" placeholder="password2" id="id_password2"/>
        <input type="address" name="address" placeholder="address" id="id_address"/>

        <input type="submit"/>

    </from>

JavaScript

<script type="text/javascript">

$(document).ready(function () {

    $('#contact-form').validate({
        rules: {
            username: {
                minlength: 5,
                required: true
            },
            email: {
                required: true,
                email: true
            },
            password1: {
                minlength: 6,
                required: true
            },
            password2: {
                required: true,
                minlength: 6,
                equalTo: "#password1",
            },
          address: {
                minlength: 5,
                required: true,

            },
        },
        highlight: function (element) {
            $(element).closest('.control-group').removeClass('success').addClass('error');
        },
        success: function (element) {
            element.text('OK!').addClass('valid')
                .closest('.control-group').removeClass('error').addClass('success');
        }
    });

   });

我想用 RegEx 模式来处理,比如/-()。,这些章程只允许使用字母我如何在这个中使用模式 RegEx?

4

1 回答 1

0

尝试这个

address: {
            minlength: 5,
            maxlenght=50,
            required: true,
            regex: /^[a-zA-Z0-9\s,'-./()]*$/,
        },
于 2017-04-20T08:22:15.113 回答