Hi,
On radmaskedtextbox, I noticed that after setting the mask as Phone Number, it accepts numeric entries of 9 or less and won't throw that as an error, even though it's not a valid phone number length. Is there a way to set this on the control's properties? Or should I have to use a regular expression validator to achieve this? And also have the error message appear inside the radmaskedtext box like radinputmager does? (see 2nd scenario)
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" Runat="server"
DisplayMask="(###) ###-####" Mask="(###) ###-####"
ValidationGroup="vgTest" ZeroPadNumericRanges="False"
AllowEmptyEnumerations="False" DisplayPromptChar="#" RoundNumericRanges="False"
Width="125px" NumericRangeAlign="Left">
Another way I tried is to create a radinputmanager and set regular expression to phone number, this will validate on single numeric entries and we like the dynamic error messages appearing inside the textbox, however, the problem with this is we don't want the users to enter the ()- characters and we only want to grab the numeric entries to store in the database.
<telerik:RegExpTextBoxSetting BehaviorID="Phone" ErrorMessage="Invalid Phone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" Validation-ValidateOnEvent="Submit" Validation-IsRequired="true" Validation-ValidationGroup="vgTest">
<TargetControls>
<telerik:TargetInput ControlID="txtPhone" />
</TargetControls>
Let me know which approach would achieve this. Sample codes appreciated. Thanks.
On radmaskedtextbox, I noticed that after setting the mask as Phone Number, it accepts numeric entries of 9 or less and won't throw that as an error, even though it's not a valid phone number length. Is there a way to set this on the control's properties? Or should I have to use a regular expression validator to achieve this? And also have the error message appear inside the radmaskedtext box like radinputmager does? (see 2nd scenario)
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" Runat="server"
DisplayMask="(###) ###-####" Mask="(###) ###-####"
ValidationGroup="vgTest" ZeroPadNumericRanges="False"
AllowEmptyEnumerations="False" DisplayPromptChar="#" RoundNumericRanges="False"
Width="125px" NumericRangeAlign="Left">
Another way I tried is to create a radinputmanager and set regular expression to phone number, this will validate on single numeric entries and we like the dynamic error messages appearing inside the textbox, however, the problem with this is we don't want the users to enter the ()- characters and we only want to grab the numeric entries to store in the database.
<telerik:RegExpTextBoxSetting BehaviorID="Phone" ErrorMessage="Invalid Phone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}" Validation-ValidateOnEvent="Submit" Validation-IsRequired="true" Validation-ValidationGroup="vgTest">
<TargetControls>
<telerik:TargetInput ControlID="txtPhone" />
</TargetControls>
Let me know which approach would achieve this. Sample codes appreciated. Thanks.
8 Answers, 1 is accepted
0
Hi Philip,
There is a straightforward way to implement your requirement using RadMaskedTextBox. You can use its client-side OnValueChanged event to check if your phone number is shorter than required, then set the error message yourself:
Check this piece out and let me know if it works for you.
Kind regards,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
There is a straightforward way to implement your requirement using RadMaskedTextBox. You can use its client-side OnValueChanged event to check if your phone number is shorter than required, then set the error message yourself:
<
ClientEvents
OnValueChanged
=
"valueChanged"
/>
function
valueChanged(sender, args)
{
if
(sender.get_value().length < 10)
{
setTimeout(
function
()
{
var
eventArgs =
new
Telerik.Web.UI.MaskedTextBoxEventArgs(args.get_newValue(), args.get_oldValue(),
null
);
sender.raise_error(eventArgs);
sender.set_value(
""
);
sender._textBoxElement.value =
"Invalid Phone"
;
}, 0);
}
}
Check this piece out and let me know if it works for you.
Kind regards,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Philip
Top achievements
Rank 1
answered on 28 Oct 2009, 10:21 PM
Thanks, Veli
It works however I don't see the "Invalid Phone" value ever show, Is this because the RadMaskedTextBox is set to mask phone numbers and will only accept numeric inputs? So, I believe I may have to find an alternate way of displaying it, like on a tooltip.
It works however I don't see the "Invalid Phone" value ever show, Is this because the RadMaskedTextBox is set to mask phone numbers and will only accept numeric inputs? So, I believe I may have to find an alternate way of displaying it, like on a tooltip.
0
Hello Philip,
I have omitted to specify that IE does not honor the value property of the HTML Input element. You need to use the innerText property instead:
Greetings,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I have omitted to specify that IE does not honor the value property of the HTML Input element. You need to use the innerText property instead:
function
valueChanged(sender, args)
{
if
(sender.get_value().length < 10)
{
setTimeout(
function
()
{
var
eventArgs =
new
Telerik.Web.UI.MaskedTextBoxEventArgs(args.get_newValue(), args.get_oldValue(),
null
);
sender.raise_error(eventArgs);
sender.set_value(
""
);
sender._textBoxElement.value =
"Invalid Phone"
;
sender._textBoxElement.innerText =
"Invalid Phone"
;
}, 0);
}
}
Greetings,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Shif
Top achievements
Rank 1
answered on 07 Feb 2012, 09:24 AM
Hi,
My MaskedTextBox is short,
How can I Show a Long Message?
Thanks
Shif
My MaskedTextBox is short,
How can I Show a Long Message?
Thanks
Shif
0
Princy
Top achievements
Rank 2
answered on 07 Feb 2012, 12:12 PM
Hello,
I am not quite sure about your scenario. I suppose you need to show large Mask in RadMaskedTextBox. One suggestion is you can try setting Width for RadMaskedTextBox based on your mask.
Thanks,
Princy.
I am not quite sure about your scenario. I suppose you need to show large Mask in RadMaskedTextBox. One suggestion is you can try setting Width for RadMaskedTextBox based on your mask.
Thanks,
Princy.
0
Shif
Top achievements
Rank 1
answered on 07 Feb 2012, 12:39 PM
Hi,
Thanks for your reply,
I have a RadMaskedTextBox is quite short, - and this is how I need it, but when I put an unvalied value I want to show a long message - not in a messagebox is there any way?
or even better for me if I click 7 - it should write 07:00 - and not like now that it writes 48:00 - How can I do it?
Thanks,
Shif
Thanks for your reply,
<
telerik:RadMaskedTextBox ID="tbtry" runat="server" SelectionOnFocus="SelectAll"
PromptChar=" " Mask="<00..48>:<00..59>" Width="30px" ZeroPadNumericRanges="true" >
<ClientEvents OnValueChanged ="houresCheck" />
</telerik:RadMaskedTextBox>
I have a RadMaskedTextBox is quite short, - and this is how I need it, but when I put an unvalied value I want to show a long message - not in a messagebox is there any way?
or even better for me if I click 7 - it should write 07:00 - and not like now that it writes 48:00 - How can I do it?
Thanks,
Shif
0
Princy
Top achievements
Rank 2
answered on 08 Feb 2012, 07:11 AM
Hello,
Try setting RoundNumericRanges property of RadMaskedTextBox as false.
Thanks,
Princy.
Try setting RoundNumericRanges property of RadMaskedTextBox as false.
Thanks,
Princy.
0
Shif
Top achievements
Rank 1
answered on 08 Feb 2012, 07:47 AM
Hi Princy,
It solved my problem!!
Lots of Thanks!
Shif
It solved my problem!!
Lots of Thanks!
Shif