User1536465747 posted
I have the following code:
<asp:Label runat="server" AssociatedControlID="txtPhoneNumber" Text="<%$Resources:Res,Label_Phone %>" />
<telerik:RadMaskedTextBox runat="server" ID="txtPhoneNumber" RenderMode="Lightweight" Skin="MetroTouch" Width="100%" DisplayMask="(+1) ### ### ## ##" Mask="(+1) ### ### ## ##" PromptChar="_" SelectionOnFocus="CaretToBeginning" RequireCompleteText="false" CausesValidation="true" ValidationGroup="Account" />
<br />
<asp:CustomValidator runat="server" ID="reqPhone" ErrorMessage="<%$Resources:Res,Alert_RequiredField %>" ControlToValidate="txtPhoneNumber" ClientValidationFunction="RequiredPhone" OnServerValidate="reqPhone_ServerValidate" ValidationGroup="Account" ForeColor="Red" Display="Dynamic" SetFocusOnError="true" />
<telerik:RadScriptBlock runat="server">
<script>
function RequiredPhone(sender, args) {
if (args.Value.length == 17 || args.Value.length == 18) {
args.IsValid = true;
}else {
args.IsValid = false;
}
}
</script>
</telerik:RadScriptBlock>
As you see I need to validate the phone number but unfortunately, this custom validator does not work at the beginning. Only if you type one or more digits and click the submit button it is invoked. Otherwise, it behaves like that the phone # is valid.
Any ideas? Thank you so much