ASPxClientEditValidationEventArgs.isValid Property
Gets or sets a value specifying whether the validated value is valid.
Declaration
isValid: boolean
Property Value
Type | Description |
---|---|
boolean |
|
Remarks
Use the isValid property to specify whether the value obtained via the ASPxClientEditValidationEventArgs.value property meets your validation criteria, and so can be posted to an editor being validated.
If the entered value is not valid, you can set the isValid property to false
. In this case, the value will not be posted to the editor and a error text specified by the ASPxClientEditValidationEventArgs.errorText property will be displayed. Or you can correct the entered value manually by setting the ASPxClientEditValidationEventArgs.value property, and leaving the isValid value set to true
. In this case, the corrected value will be written to the editor.
Example
The code sample below demonstrates how you can perform custom client-side validation to limit an permissible user age. For this purpose, the ASPxClientEdit.Validate event is handled.
function OnBirthdayValidation(s, e) {
var birthday = e.value;
if(!birthday)
return;
var today = new Date();
var msecPerYear = 1000 * 60 * 60 * 24 * 365;
var years = (today.getTime() - birthday.getTime()) / msecPerYear;
if(years < 14) {
e.isValid = false;
e.errorText = "You should be at least 14 years old.";
}
}
<dx:ASPxDateEdit ID="deBirthday" runat="server" Width="200px">
<ClientSideEvents Validation="OnBirthdayValidation" />
<ValidationSettings>
<RequiredField IsRequired="True" ErrorText="Birthday is required" />
</ValidationSettings>
</dx:ASPxDateEdit>