Bootstrap验证器电子邮件notempty

时间:2017-09-11 13:55:05

标签: jquery bootstrapvalidator

我有这个输入:

<input type="text" name="email" size="40" class="wpcf7-form-control wpcf7-text form-control input-lg" id="email" aria-required="true" aria-invalid="false" required placeholder="E-mail (obligatoriu)">

我正在使用此脚本对其进行验证:

      <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js"> </script>

效果很好但是当我清除输入但它显示仍然有效时。 这只是一个节目问题,因为它不允许我发送表格,如果它是空的。

documentation

我在这里有验证规则:

                    email: {
                    validators: {
                        notEmpty: {
                            message: 'Adresa de email este un camp obligatoriu'
                        },
                        emailAddress: {
                            message: 'Adresa de email nu este corecta'
                        }
                    }
                },

1 个答案:

答案 0 :(得分:1)

希望这有帮助。

$(document).ready(function () {
	$('#cereForm').bootstrapValidator({
		message: 'This value is not valid',
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
		fields: {
			nume: {
				validators: {
					notEmpty: {
						message: 'Numele este un camp obligatoriu'
					}
				}
			},
			email: {
				validators: {
					notEmpty: {
						message: 'Email address is mandatory'
					},
					emailAddress: {
						message: 'The input is not a valid email address'
					}
				}
			},
			telefon: {
				validators: {
					phone: {
						country: 'RO',
						message: 'Acest numar de telefon nu este corect'
					}
				}
			},
			mesaj: {
				validators: {
					notEmpty: {
						message: 'The content is required and cannot be empty'
					},
					stringLength: {
						max: 500,
						message: 'Mesajul este prea lung'
					}
				}
			},
		}
	});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.3/js/bootstrapValidator.min.js"></script>

<form id="cereForm">
	<div class="row">
		<div class="col-sm-6 col-md-6">
			<div class="form-group">
				<span class="wpcf7-form-control-wrap nume">
					<input type="text" name="nume" value="" size="40" class="wpcf7-form-control wpcf7-text  form-control input-lg" id="nume" aria-required="true" aria-invalid="false" placeholder="Nume (obligatoriu)">
				</span>
			</div>
			<div class="form-group">
				<span class="wpcf7-form-control-wrap email">
					<input type="text" name="email" size="40" class="wpcf7-form-control wpcf7-text form-control input-lg" id="email" placeholder="E-mail (obligatoriu)">
				</span>
			</div>
			<div class="form-group">
				<span class="wpcf7-form-control-wrap telefon">
					<input type="telefon" name="telefon" value="" size="40" class="wpcf7-form-control wpcf7-text form-control input-lg" id="telefon" aria-required="true" aria-invalid="false" placeholder="Telefon">
				</span>
			</div>
			<div class="form-group">
				<label class="labelformular">De la:</label>
				<div class="input-group date datepicker" id="data1" data-date-format="dd-mm-yyyy">
					<input class="wpcf7-form-control wpcf7-text  form-control input-lg data1" name="data1" type="text" readonly />
					<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
				</div>
			</div>
			<p></p>
		</div>
		<div class="col-sm-6 col-md-6">
			<div class="form-group">
				<span class="wpcf7-form-control-wrap mesaj">
					<textarea type="text" name="mesaj" class="wpcf7-form-control wpcf7-text  form-control input-lg mesaj" id="mesaj" aria-required="true" aria-invalid="false" placeholder="Mesaj"></textarea>
				</span>
			</div>
			<div class="form-group">
				<label class="labelformular">Pana la:</label>
				<div class="input-group date datepicker" data-date-format="dd-mm-yyyy">
					<input class="wpcf7-form-control wpcf7-text  form-control input-lg data2" name="data2" type="text" readonly />
					<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
				</div>
			</div>
		</div>
		<div class="col-sm-12 col-md-12">
			<input type="submit" value="Trimite mesaj" class="wpcf7-form-control wpcf7-submit">
		</div>
	</div>
</form>