symfony jquery密码验证
我想验证我的密码确认,并显示一条消息确认我的密码相同: 这是我的代码: 细枝:symfony jquery密码验证,jquery,validation,symfony,passwords,Jquery,Validation,Symfony,Passwords,我想验证我的密码确认,并显示一条消息确认我的密码相同: 这是我的代码: 细枝: {#password#} {{ form_label(form.password.first,'Votre adresse password *') }} {{ form_widget(form.password.first,{'attr':{'id':'passwd1'}}) }}<br/> {#password confirmation#}
{#password#}
{{ form_label(form.password.first,'Votre adresse password *') }}
{{ form_widget(form.password.first,{'attr':{'id':'passwd1'}}) }}<br/>
{#password confirmation#}
{{ form_label(form.password.second,'Confirmer Votre adresse password*') }}
{{ form_widget(form.password.second,{'attr':{'id':'passwd2'}}) }}<br/>
和jquery:
function validateMainForm() {
jQuery("#form_register").validate({
/*Gestion des règles de controle*/
rules: {
'contact[phone]': {
required: true,
'regex': /^0[1-9][0-9]{8}$/
},
'contact[datacontact][email][first]': {
required: true,
'email': true,
maxlength: 50
},
'contact[datacontact][email][second]': {
required: true,
'email': true,
maxlength: 50
},
'contact[password][first]': {
required: true
},
'contact[password][second]': {
equalTo:'#contact[password][first]'
},
电子邮件是正确的,但密码是no。
如何验证密码?我想显示一条消息,通知我密码和确认密码是否相同,如下所示![在此处输入图像描述][1] 这是我的表单类型的代码: 公共函数buildForm(FormBuilderInterface$builder、array$options){
我想显示一条消息,通知我密码和确认密码是否与此相同,![在此处输入图像描述][1] 这是我的表单类型的代码: 公共函数buildForm(FormBuilderInterface$builder、array$options){ } 这是我的form_小部件的代码:
{#password#} {{ form_label(form.password.first,'Votre adresse password *') }} {{ form_widget(form.password.first,{'attr':{'id':'password','name':'password'}}) }}
{#password confirmation#} {{ form_label(form.password,'Confirmer Votre adresse password*') }} {{ form_widget(form.password.second,{'attr':{'id':'password1', 'name':'password1'}}) }}
Jquery方法
jQuery.validator.addMethod("regex", function(value, element, regexp) {
if (regexp.constructor != RegExp)
regexp = new RegExp(regexp);
else if (regexp.global)
regexp.lastIndex = 0;
return this.optional(element) || regexp.test(value);
}, "");
jQuery.validator.addMethod(
'ContainsAtLeastOneDigit',
function (value) {
return /[0-9]/.test(value);
},
'Your password must contain at least one digit.'
);
jQuery.validator.addMethod(
'ContainsAtLeastOneCapitalLetter',
function (value) {
return /[A-Z]/.test(value);
},
'Your password must contain at least one capital letter.'
);
jQuery.validator.addMethod( 'passwordMatch', function(value, element) {
// The two password inputs
var pass1 = $('input[name="contact[password][first"]').attr('value');
var pass2 = $('input[name="contact[password][second"]').attr('value');
// Check for equality with the password inputs
if (pass1 != pass2 ) {
return false;
} else {
return true;
}
}, "Your Passwords Must Match");
因此,我需要显示一条消息,告知我的确认密码是否相同。您可以添加有关问题的更多详细信息吗?
$builder
->add('phone', 'text', array('error_bubbling' => true))
->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'les mots de passe ne sont pas identiques',
'options' => array('required' => true),
'first_options' => array(),
'second_options' => array(),
'error_bubbling'=>true
))
->add('datacontact', new DataContactType($this->fields));
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'contact'
));
}
public function getName() {
return 'contact';
}
{#password#} {{ form_label(form.password.first,'Votre adresse password *') }} {{ form_widget(form.password.first,{'attr':{'id':'password','name':'password'}}) }}
{#password confirmation#} {{ form_label(form.password,'Confirmer Votre adresse password*') }} {{ form_widget(form.password.second,{'attr':{'id':'password1', 'name':'password1'}}) }}
jQuery.validator.addMethod("regex", function(value, element, regexp) {
if (regexp.constructor != RegExp)
regexp = new RegExp(regexp);
else if (regexp.global)
regexp.lastIndex = 0;
return this.optional(element) || regexp.test(value);
}, "");
jQuery.validator.addMethod(
'ContainsAtLeastOneDigit',
function (value) {
return /[0-9]/.test(value);
},
'Your password must contain at least one digit.'
);
jQuery.validator.addMethod(
'ContainsAtLeastOneCapitalLetter',
function (value) {
return /[A-Z]/.test(value);
},
'Your password must contain at least one capital letter.'
);
jQuery.validator.addMethod( 'passwordMatch', function(value, element) {
// The two password inputs
var pass1 = $('input[name="contact[password][first"]').attr('value');
var pass2 = $('input[name="contact[password][second"]').attr('value');
// Check for equality with the password inputs
if (pass1 != pass2 ) {
return false;
} else {
return true;
}
}, "Your Passwords Must Match");