如何添加模式正则验证



我有一个注册表格,其中我使用了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');
        }
    });
   });

我想将正则态度模式如/- ((。,仅允许使用字母允许我如何在此中使用模式正则表达式?

尝试此

address: {
            minlength: 5,
            maxlenght=50,
            required: true,
            regex: /^[a-zA-Z0-9s,'-./()]*$/,
        },

相关内容

  • 没有找到相关文章

最新更新