用validator验证确认密码与密码是否相等

Tony Zhou   21:37:17

    本文主要解决用validator验证确认密码与密码是否相等的问题,对于validator原理和使用方法介绍不再讨论。

    1.配置消息文件 application.properties .

errors.equal = {0}  is not equal to  {1} .
    2.添加validation.xml代码.
<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
<! DOCTYPE form - validation PUBLIC
     
" -//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN "
     
" http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd " >
< form - validation >
    
< formset >         
        
< form name = " registerForm " >
            
< field property = " username "  depends = " required,minlength " >
                
< arg0 key = " login.username " />
                
< arg1 name = " minlength "  key = " ${var:minlength} "  resource = " false " />
                
< var >
                    
< var - name > minlength </ var - name >
                    
< var - value > 5 </ var - value >
                
</ var >
            
</ field >
            
< field property = " password "  depends = " required,minlength " >
                
< arg0 key = " login.password " />
                
< arg1 name = " minlength "  key = " ${var:minlength} "  resource = " false " />
                
< var >
                    
< var - name > minlength </ var - name >
                    
< var - value > 5 </ var - value >
                
</ var >
            
</ field >
            
< field property = " repassword "  depends = " required,validwhen " >
                
< msg name = " validwhen "  key = " errors.equal " />
                
< arg0 key = " login.repassword " />
                
< arg1 name = " validwhen "  key = " login.password " />
                
< var >
                    
< var - name > test </ var - name >
                    
< var - value > (password ==* this * ) </ var - value >
                
</ var >
            
</ field >
        
</ form >
        
    
</ formset >
</ form - validation >

你可能感兴趣的:(用validator验证确认密码与密码是否相等)