CodeCharge Studio |
All ASP PHP Perl ColdFusion Java C#.NET VB.NET |
This example shows how to validate a field value using the control's On Validate Event. In this case, we have a form called Form1 which contains a Text Box called TextBox1. The value of Textbox1 should be greater than 10 and smaller than 50.
Function Form1_TextBox1_OnValidate(Sender) If Form1.TextBox1.Value < 10 or Form1.TextBox1.Value > 50 Then Form1.Errors.addError("The value must be greater than 10 and smaller than 50") End if End Function
function Form1_TextBox1_OnValidate(& $sender) {
global $Form1;
if ($Form1->TextBox1->GetValue() < 10 or $Form1->TextBox1->GetValue() > 50) {
$Form1->Errors->addError("The value must be greater than 10 and smaller than 50");
}
}sub Form1_TextBox1_OnValidate() {
if ($Form1->{TextBox1}->{Value} < 10 or $Form1->{TextBox1}->{Value} > 50) {
$Form1->{Errors}->addError("The value must be greater than 10 and smaller than 50");
}
}<!---Form1_TextBox1_OnValidate---> <CFIF fldTextBox1 LT 10 OR fldTextBox1 GT 50> <CFSET strErrRegistration=strErrRegistration & "The value must be greater than 10 and smaller than 50<br>"> </CFIF>
'Form1_TextBox1_OnValidate
If TextBox1.Value < 10 or TextBox1.Value > 50 Then
errors.Add("TextBox1","The value must be greater than 10 and smaller than 50")
End if
Note: Select Integer in the Data Type property of the TextBox1 Text Box.
//Form1_TextBox1_OnValidate
if (TextBox1.Value != null && ((Int64)TextBox1.Value < 10 || (Int64)TextBox1.Value > 50)) {
errors.Add("TextBox1","The value must be greater than 10 and smaller than 50");
}
//Form1_TextBox1_OnValidate
if ( e.getControl().getValue() != null &&
(Utils.convertToLong(e.getControl().getValue()).longValue() < 10 ||
Utils.convertToLong(e.getControl().getValue()).longValue() > 50) ) {
e.getControl().addError("The value must be greater than 10 and smaller than 50");
}