This is a migrated thread and some comments may be shown as answers.

exclude 0 as first character

2 Answers 101 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
Reine
Top achievements
Rank 1
Reine asked on 18 Aug 2016, 01:29 PM

I have a five digit postal code and want to exclude zero as first character and only allow numeric values.

Html.Kendo().MaskedTextBoxFor(a => a.Postnummer)
                    .Rules(rules => { rules.Add('0', "/[1-9]/"); })
                    .Mask("00000"))

 

not working, cant type in 0 at all.

2 Answers, 1 is accepted

Sort by
0
Orlin
Telerik team
answered on 19 Aug 2016, 08:37 AM
Hello Reine,

To achieve your goal you need to use a custom mask rule. Learn more about these here:

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/maskedtextbox/overview#define-custom-mask-rules

The code for not allowing zero as the first digit will look similar to the following:

Html.Kendo().MaskedTextBoxFor(a => a.Postnummer)
                    .Rules(rules => { rules.Add('~', "/[1-9]/"); })
                    .Mask("~0000"))

This allows only digits 1-9 for the first character and 0-9 for the rest. The 0 is a predefined mask rule. You can see a list at the following URL:

http://docs.telerik.com/kendo-ui/controls/editors/maskedtextbox/overview#configuration-Rules

I hope this helps.


Regards,
Orlin
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Reine
Top achievements
Rank 1
answered on 19 Aug 2016, 08:45 AM
Thanx worked like a charm :)
Tags
MaskedTextBox
Asked by
Reine
Top achievements
Rank 1
Answers by
Orlin
Telerik team
Reine
Top achievements
Rank 1
Share this question
or