javascript 如何在Bootstrapvalidator中验证逗号或半克隆分隔的多封电子邮件的电子邮件输入字段

o4tp2gmn  于 2023-02-02  发布在  Java
关注(0)|答案(2)|浏览(135)

我有一个文本区域为多个电子邮件输入,我想验证电子邮件与引导验证程序。我不能这样做,因为有一个选项,为多个这是默认的false,我不能使它true
供参考(引导验证程序页面):http://bootstrapvalidator.votintsev.ru/validators/emailAddress/

<div class="form-group">
<label for="email" class="col-sm-4 control-label"><span class="required">*</span> Email</label>
<div class="col-sm-8">
    <textarea id="company_email" name="email" class="form-control pull-left" rows="2" placeholder="Email"></textarea>
</div>
<script type="text/javascript">
        $(document).ready(function() {
            $('#emailForm').bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    email: {
                        validators: {
                            notEmpty: {
                                message: 'Email is required and cannot be empty'
                            },
                            emailAddress: {
                                message: 'The value is not a valid email address'
                            }
                        }
                    }
                }
            }
        });
    </script>
qij5mzcb

qij5mzcb1#

从您提供的链接:
当通过HTML属性设置选项时,请记住通过设置data-bv-emailaddress=“true”来启用验证器。当使用HTML 5 type=“email”属性时,您不需要这样做。
只需将这些属性添加到文本区域即可:data-bv-emailaddress-multiple="true" data-bv-emailaddress="true"
测试一下:

$(document).ready(function() {
    $('#emailForm').bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    email: {
                        validators: {
                            notEmpty: {
                                message: 'Email is required and cannot be empty'
                            },
                            emailAddress: {
                                message: 'The value is not a valid email address'
                            }
                        }
                    }
                }
            });
});
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.5.3/js/bootstrapValidator.js"></script>
</head>
<body>


<form id="emailForm" class="form-horizontal">
    <div class="form-group">
<label for="email" class="col-sm-4 control-label"><span class="required">*</span> Email</label>
<div class="col-sm-8">
    <textarea id="company_email" name="email" class="form-control pull-left" rows="2" placeholder="Email" data-bv-emailaddress-multiple="true" data-bv-emailaddress="true"></textarea>
</div>
</form>


</body>
</html>
svujldwt

svujldwt2#

添加标签multiple,例如<input type="email" multiple>
参见https://www.stefanjudis.com/today-i-learned/email-inputs-can-accept-multiple-email-addresses/
在使用Bootstrap验证时,我允许逗号分隔的电子邮件地址。

相关问题