Home > front end >  How to give the parameters of the validation error message format
How to give the parameters of the validation error message format

Time:09-26

Asp.net MVC project c #

The validation test is as follows:
 
//on the numerical largest numerical judgement
$. The validator. AddMethod (' numbermax ', function (the value, the element, param) {

If (value="" https://bbs.csdn.net/topics/={
return true;
}
(value=https://bbs.csdn.net/topics/value.replace/,/g, "");
If (checkNumber (value)) {
Return the Number (value) & lt;=Number (param);
}
The else {
return true;
}
});
$. The validator. Unobtrusive. Adapters. AddBool (" numbermax ");


View project set as follows (appendgrid plug-ins add [numbermax] to project validation) :
 
.
{
//unit price
Name: 'UNIT_AMT'
Display: 'price',
Type: 'tel,
Min - displayCss: {' width ', '6 rem'},
CtrlAttr: {
Required: true,
Number: true,
Numbermax: 9999999
},
CtrlClass: 'text - right'
},
.


Messages_xx. Js error information is as follows:
 
Numbermax: "more than the world's largest numerical {0}",


The results are as follows:


How can I get the error message parameter format? Three (a comma)
That is:
More than the world's largest 9999999 nt

CodePudding user response:


 $(document). Ready (function () {
//on the numerical largest numerical judgement
$. The validator. AddMethod (' numbermax ', function (the value, the element, param) {

If (value="" https://bbs.csdn.net/topics/={
return true;
}
(value=https://bbs.csdn.net/topics/value.replace/,/g, "");
If (value) {
Return the Number (value) & lt;=Number (param);
}
The else {
return true;
}
}, function (a, b, c) {
Return the "big big";//this is the default prompt
});
$(" # commentForm2 "). The validate ({
Rules: {//configuration form validation rules
Numbermax: {
Required: true,
Numbermax: 999999
},
Numbermax2: {
Required: true,
Numbermax: 100
}
},
Messages: {
Email: {
Required: 'Enter this! '
},
Numbermax: {
Numbermax: function (a, b, c) {
The debugger.
Var STR=$(b). Val ();
Return "is the value of the input" + STR. Replace (/((\ d {1, 3})?=(\ d {3}) + $)/g, '$1') + 'greater than' + a;
}
}
}
});
});

 


Numbermax (999999) :



Numbermax2 (100) :







CodePudding user response:

9 lines of the if (value) to change back to your judgment logic, prompt message string can be used, or use $. The validator. The format (" {0} message string {1} "), can also be a custom function, like the above

CodePudding user response:

Hello World reference 2 floor, response:
9 lines of the if (value) to change back to your judgment logic, prompt message string can be used, or use $. The validator. The format (message string "{0} {1}"), can also be a custom function, like the above


Thank you, but I want to use appendgrid Validation for accurately verify
So I need to think about how to cover the original error message...
Your answer gave me ideas, I need to think about how to use the

https://appendgrid.apphb.com/Demo/Validation
  • Related