springmvc validate时, 如何输出带参数的message 50
用springmvc开发,进行validator时,发现validate输出的message是不能随便加参数的,可是我希望输出时能有自己定义的参数。例如,inputEma...
用springmvc 开发,进行validator时,发现validate输出的message 是不能随便加参数的,可是我希望输出时能有自己定义的参数。
例如, inputEmail 和 inputName 的非空 validate 我希望以一个message输出, w.001={0}不能为空
而在画面显示时,要显示 “ 邮箱不能为空”, “姓名不能为空”。
现在的做法,要么定义不同的message,要么只能输出 “inputEmail不能为空”。
不知有没有办法,如何配置。或者是否需要写 handle 展开
例如, inputEmail 和 inputName 的非空 validate 我希望以一个message输出, w.001={0}不能为空
而在画面显示时,要显示 “ 邮箱不能为空”, “姓名不能为空”。
现在的做法,要么定义不同的message,要么只能输出 “inputEmail不能为空”。
不知有没有办法,如何配置。或者是否需要写 handle 展开
展开全部
<script type="text/javascript">
$(function(){
checkAll();
});
function checkAll(){
var login_name = new LiveValidation('login_name',{ wait : 500},{onlyOnSubmit:true});
login_name.add( Validate.Presence, {failureMessage: "不能为空!"});
login_name.add( Validate.Length, { maximum: 50 } );
login_name.add( Validate.Custom, { failureMessage: '登录名已经存在!', against: function(value, args){
var login_name=$('#login_name').val();
var validateResult = 'yes';
$.ajaxSetup({async: false});
$.post('<%=basePath%>/user_checkUser.action', {ct : (new Date()).getTime(),'user.login_name':login_name},function(json){
validateResult=json.msg;
});
return (validateResult == 'yes');
}});
var d_name = new LiveValidation('d_name',{ wait : 500},{onlyOnSubmit:true});
d_name.add( Validate.Presence, {failureMessage: "不能为空!"});
d_name.add( Validate.Length, { maximum: 50 } );
var industy_id = new LiveValidation('industy_id',{ wait : 500},{onlyOnSubmit:true});
industy_id.add( Validate.Presence, {failureMessage: "不能为空!"});
industy_id.add( Validate.Length, { maximum: 50 } );
var last_year_income = new LiveValidation('last_year_income',{ wait : 500},{onlyOnSubmit:true});
last_year_income.add( Validate.Presence, {failureMessage: "不能为空!"});
last_year_income.add( Validate.Numericality, {failureMessage: "请输入数字"});
last_year_income.add( Validate.Length, { maximum: 50 } );
var org_code = new LiveValidation('org_code',{ wait : 500},{onlyOnSubmit:true});
org_code.add( Validate.Presence, {failureMessage: "不能为空!"});
org_code.add( Validate.Length, { maximum: 50 } );
var address = new LiveValidation('address',{ wait : 500},{onlyOnSubmit:true});
address.add( Validate.Presence, {failureMessage: "不能为空!"});
address.add( Validate.Length, { maximum: 50 } );
var postal_code = new LiveValidation('postal_code',{ wait : 500},{onlyOnSubmit:true});
postal_code.add( Validate.Presence, {failureMessage: "不能为空!"});
postal_code.add( Validate.Numericality, {failureMessage: "请输入数字"});
postal_code.add( Validate.Length, { maximum: 50 } );
var in_stal = new LiveValidation('in_stal',{ wait : 500},{onlyOnSubmit:true});
in_stal.add( Validate.Presence, {failureMessage: "不能为空!"});
in_stal.add( Validate.Length, { maximum: 50 } );
var open_bank = new LiveValidation('open_bank',{ wait : 500},{onlyOnSubmit:true});
open_bank.add( Validate.Presence, {failureMessage: "不能为空!"});
open_bank.add( Validate.Length, { maximum: 50 } );
var bank_number = new LiveValidation('bank_number',{ wait : 500},{onlyOnSubmit:true});
bank_number.add( Validate.Presence, {failureMessage: "不能为空!"});
bank_number.add( Validate.Length, { maximum: 50 } );
bank_number.add(Validate.Numericality, { notANumberMessage : "请输入数字"});
var legal_person = new LiveValidation('legal_person',{ wait : 500},{onlyOnSubmit:true});
legal_person.add( Validate.Presence, {failureMessage: "不能为空!"});
legal_person.add( Validate.Length, { maximum: 50 } );
var phone = new LiveValidation('phone',{ wait : 500},{onlyOnSubmit:true});
phone.add( Validate.Presence, {failureMessage: "不能为空!"});
phone.add(Validate.Format, { pattern:/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/i });
phone.add( Validate.Length, { maximum: 50 } );
var e_mail = new LiveValidation('e_mail',{ wait : 500},{onlyOnSubmit:true});
e_mail.add( Validate.Presence, {failureMessage: "不能为空!"});
e_mail.add( Validate.Length, { maximum: 50 } );
var business_person = new LiveValidation('business_person',{ wait : 500},{onlyOnSubmit:true});
business_person.add( Validate.Presence, {failureMessage: "不能为空!"});
business_person.add( Validate.Length, { maximum: 50 } );
var hend_phone = new LiveValidation('hend_phone',{ wait : 500},{onlyOnSubmit:true});
hend_phone.add( Validate.Presence, {failureMessage: "不能为空!"});
hend_phone.add(Validate.Format, { pattern:/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/i });
hend_phone.add( Validate.Length, { maximum: 50 } );
var fax = new LiveValidation('fax',{ wait : 500},{onlyOnSubmit:true});
fax.add( Validate.Presence, {failureMessage: "不能为空!"});
fax.add( Validate.Length, { maximum: 50 } );
var login_password = new LiveValidation('login_password',{ wait : 500},{onlyOnSubmit:true});
login_password.add( Validate.Presence, {failureMessage: "不能为空!"});
login_password.add( Validate.Length, { maximum: 50 } );
var ogin_password2 = new LiveValidation('ogin_password2',{ wait : 500},{onlyOnSubmit:true});
ogin_password2.add( Validate.Presence, {failureMessage: "不能为空!"});
ogin_password2.add( Validate.Length, { maximum: 50 } );
ogin_password2.add( Validate.Custom, { failureMessage: '输入的两次密码不一致!', against: function(value, args){
var login_password=$('#login_password').val();
var ogin_password2=$('#ogin_password2').val();
return (login_password == ogin_password2);
}});
var industy_id = new LiveValidation('industy_id',{ wait : 500},{onlyOnSubmit:true});
industy_id.add( Validate.Presence, {failureMessage: "不能为空!"});
industy_id.add( Validate.Length, { maximum: 50 } );
var in_stal = new LiveValidation('in_stal',{ wait : 500},{onlyOnSubmit:true});
in_stal.add( Validate.Presence, {failureMessage: "不能为空!"});
in_stal.add( Validate.Length, { maximum: 50 } );
var postal_code = new LiveValidation('postal_code',{ wait : 500},{onlyOnSubmit:true});
postal_code.add( Validate.Presence, {failureMessage: "不能为空!"});
postal_code.add( Validate.Length, { maximum: 50 } );
}
</script>
类型定义好了自动检测的 我自己项目中用的 采纳
$(function(){
checkAll();
});
function checkAll(){
var login_name = new LiveValidation('login_name',{ wait : 500},{onlyOnSubmit:true});
login_name.add( Validate.Presence, {failureMessage: "不能为空!"});
login_name.add( Validate.Length, { maximum: 50 } );
login_name.add( Validate.Custom, { failureMessage: '登录名已经存在!', against: function(value, args){
var login_name=$('#login_name').val();
var validateResult = 'yes';
$.ajaxSetup({async: false});
$.post('<%=basePath%>/user_checkUser.action', {ct : (new Date()).getTime(),'user.login_name':login_name},function(json){
validateResult=json.msg;
});
return (validateResult == 'yes');
}});
var d_name = new LiveValidation('d_name',{ wait : 500},{onlyOnSubmit:true});
d_name.add( Validate.Presence, {failureMessage: "不能为空!"});
d_name.add( Validate.Length, { maximum: 50 } );
var industy_id = new LiveValidation('industy_id',{ wait : 500},{onlyOnSubmit:true});
industy_id.add( Validate.Presence, {failureMessage: "不能为空!"});
industy_id.add( Validate.Length, { maximum: 50 } );
var last_year_income = new LiveValidation('last_year_income',{ wait : 500},{onlyOnSubmit:true});
last_year_income.add( Validate.Presence, {failureMessage: "不能为空!"});
last_year_income.add( Validate.Numericality, {failureMessage: "请输入数字"});
last_year_income.add( Validate.Length, { maximum: 50 } );
var org_code = new LiveValidation('org_code',{ wait : 500},{onlyOnSubmit:true});
org_code.add( Validate.Presence, {failureMessage: "不能为空!"});
org_code.add( Validate.Length, { maximum: 50 } );
var address = new LiveValidation('address',{ wait : 500},{onlyOnSubmit:true});
address.add( Validate.Presence, {failureMessage: "不能为空!"});
address.add( Validate.Length, { maximum: 50 } );
var postal_code = new LiveValidation('postal_code',{ wait : 500},{onlyOnSubmit:true});
postal_code.add( Validate.Presence, {failureMessage: "不能为空!"});
postal_code.add( Validate.Numericality, {failureMessage: "请输入数字"});
postal_code.add( Validate.Length, { maximum: 50 } );
var in_stal = new LiveValidation('in_stal',{ wait : 500},{onlyOnSubmit:true});
in_stal.add( Validate.Presence, {failureMessage: "不能为空!"});
in_stal.add( Validate.Length, { maximum: 50 } );
var open_bank = new LiveValidation('open_bank',{ wait : 500},{onlyOnSubmit:true});
open_bank.add( Validate.Presence, {failureMessage: "不能为空!"});
open_bank.add( Validate.Length, { maximum: 50 } );
var bank_number = new LiveValidation('bank_number',{ wait : 500},{onlyOnSubmit:true});
bank_number.add( Validate.Presence, {failureMessage: "不能为空!"});
bank_number.add( Validate.Length, { maximum: 50 } );
bank_number.add(Validate.Numericality, { notANumberMessage : "请输入数字"});
var legal_person = new LiveValidation('legal_person',{ wait : 500},{onlyOnSubmit:true});
legal_person.add( Validate.Presence, {failureMessage: "不能为空!"});
legal_person.add( Validate.Length, { maximum: 50 } );
var phone = new LiveValidation('phone',{ wait : 500},{onlyOnSubmit:true});
phone.add( Validate.Presence, {failureMessage: "不能为空!"});
phone.add(Validate.Format, { pattern:/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/i });
phone.add( Validate.Length, { maximum: 50 } );
var e_mail = new LiveValidation('e_mail',{ wait : 500},{onlyOnSubmit:true});
e_mail.add( Validate.Presence, {failureMessage: "不能为空!"});
e_mail.add( Validate.Length, { maximum: 50 } );
var business_person = new LiveValidation('business_person',{ wait : 500},{onlyOnSubmit:true});
business_person.add( Validate.Presence, {failureMessage: "不能为空!"});
business_person.add( Validate.Length, { maximum: 50 } );
var hend_phone = new LiveValidation('hend_phone',{ wait : 500},{onlyOnSubmit:true});
hend_phone.add( Validate.Presence, {failureMessage: "不能为空!"});
hend_phone.add(Validate.Format, { pattern:/(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/i });
hend_phone.add( Validate.Length, { maximum: 50 } );
var fax = new LiveValidation('fax',{ wait : 500},{onlyOnSubmit:true});
fax.add( Validate.Presence, {failureMessage: "不能为空!"});
fax.add( Validate.Length, { maximum: 50 } );
var login_password = new LiveValidation('login_password',{ wait : 500},{onlyOnSubmit:true});
login_password.add( Validate.Presence, {failureMessage: "不能为空!"});
login_password.add( Validate.Length, { maximum: 50 } );
var ogin_password2 = new LiveValidation('ogin_password2',{ wait : 500},{onlyOnSubmit:true});
ogin_password2.add( Validate.Presence, {failureMessage: "不能为空!"});
ogin_password2.add( Validate.Length, { maximum: 50 } );
ogin_password2.add( Validate.Custom, { failureMessage: '输入的两次密码不一致!', against: function(value, args){
var login_password=$('#login_password').val();
var ogin_password2=$('#ogin_password2').val();
return (login_password == ogin_password2);
}});
var industy_id = new LiveValidation('industy_id',{ wait : 500},{onlyOnSubmit:true});
industy_id.add( Validate.Presence, {failureMessage: "不能为空!"});
industy_id.add( Validate.Length, { maximum: 50 } );
var in_stal = new LiveValidation('in_stal',{ wait : 500},{onlyOnSubmit:true});
in_stal.add( Validate.Presence, {failureMessage: "不能为空!"});
in_stal.add( Validate.Length, { maximum: 50 } );
var postal_code = new LiveValidation('postal_code',{ wait : 500},{onlyOnSubmit:true});
postal_code.add( Validate.Presence, {failureMessage: "不能为空!"});
postal_code.add( Validate.Length, { maximum: 50 } );
}
</script>
类型定义好了自动检测的 我自己项目中用的 采纳
追问
不好意思,你真的用过springmvc吗,这和mvc的validate没什么关系。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询