exclude 0 as first character

3 posts, 0 answers
  1. Reine
    Reine avatar
    2 posts
    Member since:
    Mar 2015

    Posted 18 Aug Link to this post

    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. Orlin
    Admin
    Orlin avatar
    22 posts

    Posted 19 Aug Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Reine
    Reine avatar
    2 posts
    Member since:
    Mar 2015

    Posted 19 Aug Link to this post

    Thanx worked like a charm :)
Back to Top