不用js,怎么去判断两次输入的密码不正确?

我是想在控制器中实现,Validator这个类中但是没有这个判断啊?请大神教教!
已邀请:

kelson

赞同来自: jiangs

这是我项目中的部分片段,希望能够帮助到你。如下:
//
    $rules = array(
        'Username' => 'required|alpha_dash|min:6|max:18|unique:users,username',
        'EmailAddress' => 'required|email|unique:users,email',
        'Password' => 'required|min:8|max:18|confirmed|different:Username',
        'Password_confirmation'=>'required'
    );

    $validator = Validator::make(Input::all(),$rules);
    if ($validator->fails())
    {
        Session::flash('old',Input::only('Username','EmailAddress'));
        return Redirect::to('join')->withErrors($validator);
    }

FiveSay - 成武

赞同来自:

laravel 自带 confirmed 规则
http://my.oschina.net/5say/blog/186568#OSC_h4_20

jiangs

赞同来自:

$formData2 = array(
'password' => Input::get('password'),
'confirm-password' => Input::get('confirm_password')

);
$rules = array(
'password' => 'required|min:4',
'confirm-password' => 'confirmed|same:password'

);

$validation = Validator::make($formData2, $rules);

if ($validation->fails()) {

return Redirect::action('App\Controllers\Admin\UserController@edit', array($id))->withErrors($validation)->withInput();
}

这样子吗?但是我提交时没有错误信息

jiangs

赞同来自:

谢谢kelson,我已经处理好了,我是这样子写的,我的代码如下:
html中:
<!-- Password -->
<div class="control-group {{ $errors->has('password') ? 'has-error' : '' }}">
<label class="control-label" for="password" style="font-size: 16px;">密码:</label>
<div class="controls">
{{ Form::password('password', array('class'=>'form-control', 'id' => 'password', 'placeholder'=>'Password', 'value'=>Input::old('password'))) }}
@if ($errors->first('password'))
<span class="help-block">{{ $errors->first('password') }}</span>
@endif
</div>
</div>
<br>
<!-- Confirm Password -->
<div class="control-group {{ $errors->has('confirm-password') ? 'has-error' : '' }}">
<label class="control-label" for="confirm-password" style="font-size: 16px;">确认密码:</label>
<div class="controls">
{{ Form::password('confirm_password', array('class'=>'form-control', 'id' => 'confirm_password', 'placeholder'=>'Confirm Password', 'value'=>Input::old('confirm_password'))) }}
@if ($errors->first('confirm-password'))
<span class="help-block">{{ $errors->first('confirm-password') }}</span>
@endif
</div>
</div>
<br>
控制器中:
$formData2 = array(
'password' => Input::get('password'),
'confirm-password' => Input::get('confirm_password')

);
$rules = array(
'password' => 'required|min:4',
'confirm-password' => 'required|same:password'

);

$validation = Validator::make($formData2, $rules);

if ($validation->fails()) {

return Redirect::action('App\Controllers\Admin\UserController@edit', array($id))->withErrors($validation)->withInput();
}

刚开始我在html中用的是,Form::text导致不能提示两次密码不一致,当我换成Form::password时就可以了,当我输入两次密码不一致时,出现提示信息了

在此非常感谢两位大神!
kelson和FiveSay

赵狗胜 - 谢谢帮助过我的人!

赞同来自:

$email = Input::get('email');
    $password = Input::get('password');
    $password_confirmation = Input::get('password_confirmation');
    $sex = Input::get('sex');
    //dd(Input::all());
    //验证数据
    $validator = Validator::make(
        array('email' => $email,
                'password' => $password,
                'password_confirmation' => $password_confirmation
                ),
        array('email' => 'required|email',
                'password' => 'required|alpha_num|between:6,12|confirmed'
                )
    );

要回复问题请先登录注册